I've made a simple console game just for fun, but I cant get random() or mult() to work.
Heres the code how it would work:
Code:
#include <iostream.h>
#include <fstream.h>
#include <iostream>
#include <fstream>
int main()
{
int input;
cout<<"--Main Menu--"<<endl;
cout<<"1. Play Game"<<endl;
cout<<"2. Exit"<<endl;
cout<<"Please enter your option: ";
cin>>input;
switch (input)
{
case 1:
int input2;
int x;
int y;
int z;
x=1;
y=2;
z=2;
cout<<"What is "<<x<<"x"<<y<<endl;
cin>>input2;
switch (input2)
{
case 2:
cout<<"Congratulations you have won!"<<endl;
return 0;
default:
cout<<"Sorry, you have lost"<<endl;
return 0;
}
case 2:
return 0;
default:
cout<<"Error! Exiting Game!"<<endl;
return 0;
}
return 0;
}
But i want it to look like this:
Code:
#include <iostream.h>
#include <fstream.h>
#include <iostream>
#include <fstream>
int main()
{
int input;
cout<<"--Main Menu--"<<endl;
cout<<"1. Play Game"<<endl;
cout<<"2. Exit"<<endl;
cout<<"Please enter your option: ";
cin>>input;
switch (input)
{
case 1:
int input2;
int x;
int y;
int z;
x=random(10);
y=random(10);
z=mult(int x, int y);
cout<<"What is "<<x<<"x"<<y<<endl;
cin>>input2;
switch (input2)
{
case z:
cout<<"Congratulations you have won!"<<endl;
return 0;
default:
cout<<"Sorry, you have lost"<<endl;
return 0;
}
case 2:
return 0;
default:
cout<<"Error! Exiting Game!"<<endl;
return 0;
}
return 0;
}
Note that int x and y are random, and z is the product of x and y.
Can anyone help me? Im a beginner by the way