Re: switch/case & functions
Code:
#include <iostream.h>
#include <conio.h>
void playgame(int a);
void loadgame(int b);
void multiplayer(int c);
int main()
{
int input;
cout<<"1. Play game"<<endl;
cout<<"2. Load game"<<endl;
cout<<"3. Play multiplayer"<<endl;
cout<<"4. Exit"<<endl;
cin>>input;
switch (input)
{
case 1:
playgame(1);
break;
case 2:
loadgame(2);
break;
case 3:
multiplayer(3);
break;
case 4:
return 0;
default:
cout<<"Error, bad input, quitting"<< endl;
}
}
void playgame(int a)
{
if (a==1) //parse error before 'if'
{
cout << "Game loading..." endl;
}
}
void loadgame(int b)
{
if (b==2)
{
cout << "Loading saved game..." << endl;
}
}
void multiplayer(int c)
{
if (c==3)
{
cout <<"Multiplayer game loading..." << endl;
}
}
One more thought/comment for you, Torsin
An if-statement is not an expression. It doesn't evaluate to anything, or return anything.
This means that you can't write: x = if(A==B0);