I wrote this C ++ code in the CodeBlocks IDE, but when I run it, it does not give me -1, if it does not read the number, it gives me 0. Is there something wrong with the code?
#include "iostream" using namespace std; int main() { cout<<"Please enter your first name and age:\n"; string first_name="???"; //string variable //("???" means "don't know the name") int age=-1; //integer variable (-1 means "don't know the age") cin>>first_name>>age; //read a string followed by an integer cout<<"Hello, " <<first_name<<" (age "<<age<<")\n"; return 0; }
c ++ c ++ 11
Alberto
source share