Author Topic: Confusing error  (Read 7009 times)

stolsig55

  • Guest
Confusing error
« on: January 10, 2012, 04:36:26 am »
Sorry if this come of as trivial, but while I am currently trying to learn code, I am frustrated by an error message that seems to make no sense.

I receive the error: 'else' without a previous 'if'

But there is an if right above the else.


   cin >> drink;

   if ( drink == 1 );
   cout << "You selected Dr. Pepper. Thank you for completing the survey.";
   else if (drink == 2);
   cout << "you selected Sprite. Thank you for sompleting the survey.";


Help would be greatly appreciated

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Confusing error
« Reply #1 on: January 10, 2012, 05:06:43 am »
You are posting in the wrong forum!  This forum is not meant for direct programming questions.
Try searching Google for "C++ forum".

However, your problem is this:
   cin >> drink;

   if ( drink == 1 );
   cout << "You selected Dr. Pepper. Thank you for completing the survey.";
   else if (drink == 2);
   cout << "you selected Sprite. Thank you for sompleting the survey.";