Well, I started with switches, and completely understand them and how they work. But, I have 2 errors when trying to compile my improved number game. Here is the code:
Code:
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
int main()
{
//loop count
int loopCount;
cout<<"Enter number of guesses you wish to make:\n";
cin>> loopCount;
//entering guesses
while(loopCount>0)
{
loopCount=loopCount--;
int guess;
cout<<"Enter a guess:\n";
cin>> guess;
if(guess==88)
{
cout<<"That is correct! Press any key to exit.\n";
getch();
break;
}
else
switch(guess)
{
if(guess>88)
{
//lower
cout<<"That is incorrect. The number is lower. Only "<<loopCount<<" guesses remaining.\n";
break;
else
//higher
cout<<"That is incorrect. The number is higher. Only "<<loopCount<<" guesses remaining.\n";
break;
}
break;
}
}
return 0;
}
The errors I get are:
number.cpp(37)Error: parse error before 'else'
number.cpp(32)Error: Warning: unreachable code at beginning of switch statement
I have no idea how to fix either of those. I've been toying around with them for quite a while, but I'm clueless.