cin >>

Hello,

I started a few days ago with C++ and I started working on my project, but I can't get it to work. I want to have cin >> for 3 cout lines.


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
30
31
32
33
#include <cstdlib>
#include <iostream>

using namespace std;

int choose1;
int choose2;
int choose3;



int main(int argc, char *argv[])
{
    cout << "Welcome to DayZ Epoch Trader Generator - Chernarus Edition\n"; 
    cout << "Choose your category:\n";
    
    cout << "1. Weapons\n";
    cout << "2. Vehicles\n";
    cout << "3. Items\n";
    cin >> choose1, choose2, choose3;
    
    

    
    
    
    
    
    getchar();
    
    system("PAUSE");
    return 0;
}
Last edited on
You want the input (insertion) operator, not the comma operator.

 
  cin >> choose1 >> choose2 >> choose3;


Thanks, but how do I bind them to the code above it, since I want people to type 1,2 & 3.

Thanks.
I'm confused. You want the user to choose one of the following, but you're inputting three values.

Do you mean something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
  int choice;
...
  cin >> choice; 
  switch (choice) 
  {
  case 1:  // Do something if the user entered 1
                break;
  case 2:  // Do something if the user entered 2
                break;
  case 3:  // Do something if the user entered 3
               break;
  default:  cout << "Valid choices are 1-3" << endl;
}


Give an example that what you want?
I'm sorry that I'm confusing you guys.

My meaning:

Console pops up:

Asks what they want;
1. weapons
2. vehicles
3. items

If they put 1, then the stuff for 1 pops up.
If they put 2, the stuff for 2 pops up.
If they put 3, that stuff pops up.
Simple conditional..
1
2
3
4
5
6
7
8
9

    int option;
    
    cin>> option;
    
    if (option == 1) cout << "1. Weapons\n";
    else if (option == 2) cout << "2. Vehicles\n";
    else if (option == 3) cout << "3. Items\n";
Thank you very much, cronopio!
your accept PM?
I do now :)
thanks, review your inbox..
Topic archived. No new replies allowed.