when i write my code its all good until the second time i use the if statment it doesent even allow for you to put yes or no its just reads the first if (great,you should....)can anybody help me im still a beginner and new to c++ and explaining why it work or doesent would mean a lot so i dont make the same mistake twice
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "hello and welcome to c++" << endl
<< endl;
cout << "whats your name?" << endl;
string name;
cin >> name;
cout << endl;
cout << "hello " << name << ",whats your last name?" << endl
<< endl;
string last;
cin >> last;
cout << endl;
cout << " " << name << " " << last << " thats a pretty name" << endl
<< endl;
cout << "how old are you?" << endl;
int age;
cin >> age;
cout << endl;
{
if (age < 18)
cout << "wow youre so young" << endl;
else if (age >= 18 && age < 30)
cout << "young adult eh" << endl;
else if (age > 30)
cout << "were always young at heart" << endl;
else
cout << "dont wanna say?ah to bad" << endl;
}
cout << "did you take a shower today?" << endl;
string input;
{
int yes, no;
if (input.compare("Yes"))
cout << "great,you should shower everyday" << endl;
else if (input.compare("No"))
cout << "ou really?You know you should shower everyday" << endl;
else
cout << "weird question right hahah" << endl;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire