Hi! Well im new to programming in general and have super basic knowledge so im pretty confused right now. You see whenever I run the code below, I can go through all of the questions normally until after the user inputs the answer to the "Ah i see, you have much to learn" cout. It suddenly skips all other user inputs after that and im not sure why. See what I want it to do is if you say yes to the "did you know you were special?" part and "Are you sure?" part then it would use the "If" "else" statement. But instead it skips all the through and ends the program. Ive tried taking out return 0; and other things and rewriting but it doesnt work. Super confused! Help? :) Thanks!
#include <iostream>
usingnamespace std;
int main()
{
string name;
string feel;
string answer;
int yes;
int no;
cout << "How are you today?" << endl;
cin >> feel;
cout << "What is your name?" << endl;
cin >> name;
cout << "Ah I see. You have much to learn." << endl;
cin >> answer;
cout << "Well, you see, you are very special, did you know that? Type 1 for yes or 2 for no." << endl;
cin >> yes;
cout << "Are you sure? Type 1 for yes or 2 for no." << endl;
cin >> yes;
if(yes == yes) {
cout << "Alright. Then lets get started " << name;
}else {
cout << "Well then I must be mistaken. Sorry";
}
}
Here if(yes == yes)
i must be so if(yes == 1)
Also why do you insert yes two times?
1 2 3 4 5 6 7
cout << "Well, you see, you are very special, did you know that? Type 1 for yes or 2 for no." << endl;
cin >> yes;
cout << "Are you sure? Type 1 for yes or 2 for no." << endl;
cin >> yes;
Because its the way i set it up for the program to make a decision. if 1=1 then its going to say okay lets get started if 1=2 then that means i must be mistaken. And I dont understand what you are trying to tell em today. Can you be more clear please?
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
cout << "How are you today?" << endl;
string feel;
cin >> feel;
cout << "What is your name?" << endl;
string name;
cin >> name;
cout << "Ah I see. You have much to learn." << endl;
string answer;
cin >> answer;
cout << "Well, you see, you are very special, did you know that? Type 1 for yes or 2 for no." << endl;
int first_answer ;
cin >> first_answer;
cout << "Are you sure? Type 1 for yes or 2 for no." << endl;
int second_answer ;
cin >> second_answer;
constint yes = 1 ;
// const int no = 2 ;
if( first_answer == yes && second_answer == yes )
{
cout << "Alright. Then lets get started " << name;
}
else
{
cout << "Well then I must be mistaken. Sorry";
}
}
Ohhhhhh okay so thats what i must have been doing. because when it would ask me something I would reply with "Im doing quite well." Lol. Okay so that makes sense now. thank you.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
cout << "How are you today?" << endl;
string feel;
std::getline( cin, feel ) ; // // type in: "Thank you, I'm fine," <enter>
cout << "What is your name?" << endl;
string name;
std::getline( cin, name ); // type in: "My name is Bleh101" <enter>
cout << "Ah I see. You have much to learn." << endl;
string answer;
std::getline( cin, answer ); // type in: "Yes, I know that." <enter>
cout << "Well, you see, you are very special, did you know that? Type yes or no." << endl;
string first_answer ;
std::getline( cin, first_answer );
cout << "Are you sure? Type yes or no." << endl;
string second_answer ;
std::getline( cin, second_answer ) ;
const string yes = "yes" ;
if( first_answer == yes && second_answer == yes )
{
cout << "Alright. Then lets get started " << name;
}
else
{
cout << "Well then I must be mistaken. Sorry";
}
}
@JLBorge; Yeah I figured it out. i rewrote it last night and it came out perfect. Love these forums, sure ill be posting more on here as well! Thanks a lot:)
You could also use if (yes = "yes") if you set up the program like that.
Is getline(cin, mystring) the same as std::getline(cin, mystring) . I know the latter.