0

In c++ how do i build up variables for 1 letter and then when i have that letter as input it should pick one of the variables

23rd Jun 2020, 6:00 AM
C0D3 BU113T
C0D3 BU113T - avatar
3 Réponses
0
the char variable is suitable for this. For example, like this: int main() { char i = 'o'; char p = 'h'; int x; cout << "select letter" << endl; if (x == 1) { cout << "letter = " << i << endl; } if(x == 2) { cout << "letter = " << p << endl; } return 0; }
23rd Jun 2020, 7:36 AM
Alexander
Alexander - avatar
0
So what would i input here
23rd Jun 2020, 7:37 AM
C0D3 BU113T
C0D3 BU113T - avatar
0
In this case, you must enter a variable to select one of the letters. I can offer another option: int main() { int x = // your number int y = // your number; char i; cin >> i; if (your logics) { cout << x << endl; } if (your logics) { cout << y << endl } else { cout << "wrong input" << endl; } return 0; } here the letter is entered that the user entered, and according to the logic conceived, one of the conditions is met.
23rd Jun 2020, 7:51 AM
Alexander
Alexander - avatar