If statement not working

Right so I am doing one of the programs which test your C++ skills on the forum and I have to have 5 different drinks and let the user pick one of them by entering 1, 2, 3, 4, 5.

I tried just doing it with one option for now but the program just ends as soon as I run it.

This is my code so far
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main() {
	int drinkNumber;	
	
	cout << "What drink would you like? Type one for Coke, two for Water, three for Sprite, four for Fanta and five for Irn Bru. "<<endl;
	
	if (drinkNumber == 1) {
		
		cout << "You have chosen Coke. ";
		
	}
	
	return 0;

}


Thanks in advance.

Arcadiu
Last edited on
You are declaring 'drinkNumber' and testing 'drink'. You aren't getting user input
Ah I know why :) thanks anyway
Last edited on
heres an example of what you want it too look like.

You need to get some input from the user which will be stored in the variable drinkNumber. which is then compared in the if statment.

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 <windows.h>

using namespace std;

int main ()

{
	int drinkNumber;

	cout << "Please choose a drink. 1 for coke, 2 for whatever etc\n\n\n";

	cin >> drinkNumber;

	if (drinkNumber == 1)

		cout << "enjoy it mate \n";

	else

		cout <<" error";

	system ("PAUSE");

	return 0;

}

Topic archived. No new replies allowed.