I am just starting out in c++, I want to make a game to tell you your fortune... very simple obviously. It will ask you to choose from 2 numbers and whatever one you pick gives you a specific answer... I am using DevC++. Please take a look at my code and tell me how to fix it, as I get a build error. Thanks!
CODE SHOWN BELOW:
#include <iostream>
using namespace std;
int numbers(int num1)
{
return num1
}
int main()
{
cout << "What is your favorite number 1 or 2";
cin >> number1;
cout << "You will die before age 50";
Thanks but I actually fixed that issue! I have a question for you though... I re wrote this program and I want to make it choose randomly in a sense from like an option bank so the user does not get the same answer for choosing say 1 for example every time... this runs error free BTW.
CODE BELOW:
#include <iostream>
using namespace std;
int main()
{
int Choice;
printf( "What is your favorite number \n\n\n\n" );
printf ( "1\n" );
printf ( "2\n" );
printf( "You Choose? " );
scanf( "%d", &Choice );
if( Choice == 1 )
printf (" You will die in 4 days \n" );
if( Choice == 2 )
printf (" You will live a long life \n" );
there's a button under format (when you point to it it says "source code") you should put your code in to it so its more legible.
and you will need to use a random number generator.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
usingnamespace std;
int randNumber();
int main(){
srand(time(NULL));
int Choice;
cout << "What is favorite number?\n\n";
cout << "1\n2\n";
cin >> Choice;
cout << "You choose: " << Choice;
Choice = randNumber();
if (Choice == 1)
cout << "You will die in 4 days )-:" << endl;
else
cout << "You will live a long life (-:" << endl;
system("PAUSE") // ii think you're using windows
return 0;
}
int randNumber(){
return rand() % 2;
}
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
usingnamespace std;
int main()
{
srand(time(NULL));
int Choice, rand_numb;
rand_numb = rand()%1+2; //it might be 2+1 I can't remember
cout << "What is favorite number?\n\n";
cout << "1\n2\n";
cin >> Choice;
cout << "You choose: " << Choice;
Choice = rand_numb;
if (Choice == 1)
cout << "You will die in 4 days )-:" << endl;
else
cout << "You will live a long life (-:" << endl;
cin.get(); //even if ur using windows
return 0;
}