I was testing out Visual studio code for C++, and was writing a madlibs code, but when I compile and execute my code in terminal it outputs something totally bizarre .
I tried different IDEs and they all worked fine except VScode
#include <iostream>
int main()
{
std::string CharacterName;
int CharacterAge;
std::string CharacterNationality;
std::string CharacterRace;
std::cout << "Enter your name: ";
std::cin >> CharacterName;
std::cout << "Enter your age: ";
std::cin >> CharacterAge;
std::cout << "Enter your nationality";
std::cin >> CharacterNationality;
std::cout << "Enter your race: ";
std::cin >> CharacterRace;
if(CharacterAge > 100)
{
std::cout << "Not valid number";
}
else
{
std::cout << "Hi! My name is " << CharacterName << ". I am " << CharacterAge << " years old." << "\n";
std::cout << "I am " << CharacterNationality << " and I am " << CharacterRace << "\n";
}
return 0;
}
Here is the error I'm getting:
I expected the code to execute in order of the commands but I misses other commands like inputing other requirements from the user. Here's the result I've been getting:
johnphillip@Johns-MacBook-Pro-2 my_cpp_projects % ./a.out
Enter your name:
John Phillip
Enter your age:
Enter your nationalityEnter your race:
Hi! My name is John. I am 0 years old.
I am and I am
johnphillip@Johns-MacBook-Pro-2 my_cpp_projects % g++ madlibs.cpp
johnphillip@Johns-MacBook-Pro-2 my_cpp_projects % ./a.out
Enter your name: John Phillip
Enter your age: Enter your nationalityEnter your race: Hi! My name is John. I am 0 years old.
I am and I am