cs31day5 Wk2 F

cs31day5 Wk2 F - What is your name? Sir Robin What is your...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: What is your name? Sir Robin What is your quest? To seek the Holy Grail Hello, brave Sir Robin! You want To seek the Holy Grail #include <iostream> #include <string> using namespace std; int main() { cout << "What is your name? "; string personsName; getline(cin, personsName); cout << "What is your quest? "; string quest; getline(cin, quest); cout << "Hello, brave " << personsName << "!" << endl; cout << "You want " << quest << endl; _________________ What is your name? Sir Robin How old are you? 32 What is your quest? To seek the Holy Grail Hello, brave Sir Robin! You want To seek the Holy Grail If you live, next year you will be 33 #include <iostream> #include <string> using namespace std; int main() { cout << "What is your name? "; string personsName; getline(cin, personsName); cout << "How old are you? "; int age; // initial number is random unless specified cin >> age; // problem here. It will consume "32" but not // the (new line(enter)) cout << "What is your quest? "; string quest; getline(cin, quest); cout << "Hello, brave " << personsName << "!" << endl; cout << "You want " << quest << endl; cout << "If you live, next year you will be " << age+1 << endl; } This will not behave correctly. It will show: What is your name? Sir Robin How old are you? 32 What is your quest? Hello, brave Sir Robin! You want If you live, next year you will be 33 _______________ #include <iostream> #include <string> using namespace std; int main() { cout << "What is your name? "; string personsName; getline(cin, personsName); cout << "How old are you? ";cout << "How old are you?...
View Full Document

This note was uploaded on 02/02/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 7

cs31day5 Wk2 F - What is your name? Sir Robin What is your...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online