为什么这告诉我我的cout和我的回复是语法错误?

时间:2014-10-25 03:32:38

标签: c++ visual-c++ syntax-error

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int NUM_GAME = 3;

int main ( void )
{

 int score1 = 0;
 int score2 = 0;
 int score3 = 0;
 int total = 0;
 double average = 0;
 char repeat;
 string name, dummy;

 //Allow user to run program again
 do
 {
//Resets total to process another game if desired
total = 0;

cout << "\nBowler #1's name: ? ";   //Reads name
getline(cin, name);

   do
   {
     cout << "\nEnter"<<name<<"'s score for each of the following games:";
     cin >> score1;
     cin >> score2;
     cin >> score3;
     if(score1 < 0 || score1 > 300 || score2 < 0 || score2 > 300 || score3 < 0 || score3 > 300 )
       cout << "\n\n*** INVALID SCORE ENTERED! Please try again. ***";
   while(score1 > -1 && score1 < 301 || score2 > -1 && score2 < 301 || score3 > -1 && score3 <         301);
   total = score1 + score2 + score3;
   }

  cout << setprecision(2) << fixed << showpoint;

//Calcualtes the average sales for the salesperson
average = total / NUM_GAME;
cout << "\n\nThe bowling average for " << name  << " is " << average << endl << endl;

cout << "\nWould you like to calculate the average for another Game? Y or N ";
cin >> repeat;
getline(cin, dummy);
while (repeat == 'y' || repeat == 'Y');
}
return 0;
}

请原谅我的格式问题和粗糙的东西 这提出了2个错误:

error C2061: syntax error : identifier 'cout'
error C2059: syntax error : 'return'
像我说的那样粗糙,解决方案可能是非常明显的,但我是新的,我还在学习绳索

2 个答案:

答案 0 :(得分:3)

首先,更好地缩进代码。

其次,

do
{

    while (repeat == 'y' || repeat == 'Y');
}

可能不是你想要的。

答案 1 :(得分:1)

do...while应为

do
{
  //code
}while(...);

而不是

do
{
  //code
  while(...);
}

你必须在while之前关闭它的身体。所以修改你的循环然后,错误就会消失。