+ 1

Why this code doesn't want to work?

https://code.sololearn.com/cyO7f3UIPaoK/?ref=app

25th Feb 2019, 6:21 PM
Igor Kirsanov
Igor Kirsanov - avatar
4 Answers
+ 2
#include <iostream> using namespace std; char name; char surname; char hobby; int age; int main() { cout << "What is your name?" << endl; cin >> name; cout << "What is your surname?" << endl; cin >> surname; cout << "How old are you?" << endl; cin >> age; cout << "What is your favorite hobby?" << endl; cin >> hobby; cout << "Your name: " << name << ". Your surname: " << surname << ". Age: " << age << " years. Your favorite hobby- " << hobby << endl; cout << "Thank you for your time" << endl; return 0; } This is a working version that I modified. I mainly changed the strings to global variables and took away the (>> endl;) When you use cin you dont need to include the endl, just the break on the variable your trying to receive. Also keep in mind that if the user dose not input anything for one of the cin requests it wont go through.
25th Feb 2019, 6:40 PM
Cypher Red
Cypher Red - avatar
+ 1
When you call cin stream, do : cin >> age; BUT NEVER : cin >> age >> endl; That's the same for all your inputs
25th Feb 2019, 6:32 PM
Théophile
Théophile - avatar
+ 1
Thanks :)
25th Feb 2019, 6:39 PM
Igor Kirsanov
Igor Kirsanov - avatar
0
I understand. Thanks :]
25th Feb 2019, 6:42 PM
Igor Kirsanov
Igor Kirsanov - avatar