Terminal 我一直从cin.get()获得程序中的空间
这是我的节目:Terminal 我一直从cin.get()获得程序中的空间,terminal,compilation,c++,Terminal,Compilation,C++,这是我的节目: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; #define RAND(a,b) (a + rand()% (b-a+1)) int main() { int num; int computer_total = 0, players_total = 0; string name; srand(ti
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
#define RAND(a,b) (a + rand()% (b-a+1))
int main()
{
int num;
int computer_total = 0, players_total = 0;
string name;
srand(time(NULL));
for(;;)
{
cout <<"What's your name? ";
cin >> name;
cin.get();
if(name == "stop")exit(0);
for(int i =0; i < 5; i++)
{
cout << name <<" roll the dice.\n";
cin.get(); //skips the cin.get() the first time aroun
num = RAND(1,6); //Also makes akward spacing
players_total += num;
cout <<"You got: " << num << endl;
cout <<"Now it's the computers turn.\n";
cin.get();
num = RAND(1,6);
computer_total += num;
cout <<"Computer got: " << num << endl;
}
cout <<"Total of computers dice: " << computer_total << endl;
cout <<"Total of your dice: " << players_total << endl;
if(computer_total == players_total)cout <<"Its a tie! \n";
else if(computer_total > players_total)cout <<"Computer won.\n";
else if(computer_total < players_total)cout <<"You won!\n";
//Do I need an else here?
}
return(0);
}
#包括
#包括
#包括
使用名称空间std;
#定义RAND(a,b)(a+RAND()%(b-a+1))
int main()
{
int-num;
int计算机总数=0,玩家总数=0;
字符串名;
srand(时间(空));
对于(;;)
{
姓名;
cin.get();
如果(名称==“停止”)退出(0);
对于(int i=0;i<5;i++)
{
cout好吧,如果你按enter键,它就会保持打印状态(这就是这一行的来源)。使用一些无回声功能,当然可以。
哦,关于跳过第一个输入,请在获取之前使用cin.ignore()
//我这里还需要别的吗
不