There is a problem with the last part of the code, the else cout << "invalid choice", it doesn't say invalid whenever the user type any other response besides the y/n. Even if the user answers the questions correctly, both the last question "what's your friends name" and the second question are asked simultaneously. And like before despite what the user types, the "invalid choice" does not pop up nor does the last statement. Heres an image to show you what I mean about the last question and the second question.This is what happens, at the end of the code.
#include "stdafx.h"
#include "iostream"
#include"string"
using namespace std;
int main()
{
string first_name;
string friends_name;
string input;
cout << " Please enter your first name (followed by 'enter'):\n";
cin >> first_name;
cout << "Hello," << first_name << " do you like where you are right now in life (y/n)?:\n";
cin >> input;
if (input == "y")
cout << "what do you like about it over,the people?(y/n)";//?:\n"
else if (input == "n")
cout << " what do you hate about it,the expenses?(y/n)";
else cout << "invalid choice";
cout << " what was your friends_name again ?" << endl;
cin >> friends_name;
cout << " Yes, I remember " << friends_name << "you should bring him more often" << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire