whats wrong here?

#include<iostream>
what do you think is wrong with this code?


using namespace std;

int main() {
int number;
char symbol;
cout << "Enter a number:\n";
cin >> number;
cout << "Enter a letter;\n";
cin.get(symbol);
cout << number << " " << symbol << endl;
system("pause");
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;

int main()
{
    int number;
    char symbol;
    
    cout << "Enter a number:\n";
    cin >> number;
    
    cin.get(); //<-add this here! (to get the '\n' after the number)
    
    cout << "Enter a letter;\n";
    cin.get(symbol);
    
    cout << number << " " << symbol << endl;
    system("pause");
    return 0;
}
It makes more sense to use ignore than get, imo.
Topic archived. No new replies allowed.