look at this..
It doesn't give me time to type address..Code:#include <iostream> int main() { using namespace std; cout << "What year was your house built?\n"; int year; cin >> year; cout << "What is its street address?\n"; char address[80]; cin.getline(address, 80); cout << "Year built: " << year << endl; cout << "Address: " << address << endl; cout << "Done!\n"; return 0; }
output is something like this
Why it doesn't ask for address?Code:What year was your house built? 1966 What is its street address? Year built: 1966 Address Done!
Answer; after giving to inti_g_er as we press "Enter key" there comes a new line character in input queue that is transfered to address.. that's why it is not give us time to type address..
OK...
but what if i assign address as a char(just as an experiment since address can't be a character)
this time it asks for address variable...Code:#include <iostream> #include<cstring> int main() { using namespace std; cout << "What year was your house built?\n"; int year; cin >> year; cout << "What is its street address?\n"; char address; cin>>address; cout << "Year built: " << year << endl; cout << "Address: " << address << endl; cout << "Done!\n"; return 0; }
why new line character is not transferred to address variable in this case???????????????????Code:What year was your house built? 1966 What is its street address? P Year built: 1966 Address P Done!




Reply With Quote