-1

I have looked at about 15 pages and corrections of this problem but just can't crack it. If someone could advise I would be eternally grateful!

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
 {
   int exres = 100;

   if (exres = 100)
   {
      cout << "Perfect Score!";
      else
      cout << "try again";
   }    


system("PAUSE");
return EXIT_SUCCESS;
}
MattLuka
  • 53
  • 7

2 Answers2

4

Your if statement syntax is incorrect. Each part of the if statement should be in its own block (within { and }s).

if (exres == 100)
{
   cout << "Perfect Score!";
}
else
{
   cout << "try again";
}

If the blocks each consist of a single statement (as they do in this case), then the braces can be omitted altogether:

if (exres == 100)
   cout << "Perfect Score!";
else
   cout << "try again";

However, I recommend using braces at all times.

Notice also that your assignment operator (=) should be the equality operator (==) instead.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
0

You made two errors. The else statement has no a corresponding if statement and instead of the comparison operator you used the assignment operator in statement

  if (exres = 100)

Also I would insert endl in output statements

   if ( exres == 100)
   {
      cout << "Perfect Score!" << endl;
   }
   else
   {
      cout << "try again" << endl;
   }    

Also nobody is able to repeat the attempt because you set yourself the value of exres. I would write the program the following way

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   while ( true )
   {
      cout << "Enter your score: ";
      unsigned int exres = 0;

      cin >> exres;

      if ( exres == 0 ) break;

      if ( exres == 100)
      {
         cout << "Perfect Score!" << endl;
      }
      else
      {
         cout << "try again" << endl;
      }
   }    


   system("PAUSE");

   return EXIT_SUCCESS;
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335