Need help making a game

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";






system("PAUSE");
return EXIT_SUCCESS;
}
Last edited on
Build errors are nifty because they not only tell you exactly what line of code the error is on, but also what the problem is.

So what does the error actually say?

EDIT:

Anyway, I actually see 2 problems.

1) You're missing a semicolon after your return num1 statement.

2) you are doing cin >> number1; in main, but you never declared number1.


Also, your numbers function literally does nothing and is never used.
Last edited on
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" );


system("PAUSE");
return EXIT_SUCCESS;
}
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.
and cout cin and cin.get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
using namespace 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;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>

using namespace 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;	
}
Topic archived. No new replies allowed.