In this program I am asking the user to input his/her name, but, in the final few lines, I ask the user whether their full name is so and so. If it is true, type true, if not, type false. I tried to do this with a Boolean value called validation. I ask the user to input true or false. If they typed "true" it will print out their full name. If they input "false", the goto statement will take them back to the start of the program and ask them to start again. But, when I run this program, I tested true and false, but, on both occasions the the console printed out their full name even through I inputted false. Also, I don't think my goto statement is working. Please look at my code and tell me what I did wrong. Thanks for reading.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first;
string last;
bool validation;
restart:
cout <<"What is your first name?" << endl;
getline (cin,first);
cout << endl;
cout << endl;
cout << endl;
cout << first << endl;
cout << endl;
cout << endl;
cout << endl;
cout <<"What is your last name?" << endl;
getline (cin,last);
cout << endl;
cout << endl;
cout << endl;
cout <<"Is your full name" << " " << first << " " << last << "?" << endl;
cout <<"True/False" << endl;
cin >> validation;
if(validation = true)
cout <<"Your full name is" << " " << first << " " << last <<"." << endl;
else if(validation = false)
goto restart;
TheGrayWolf, I tried using == too but it still does not work. And, metulburr, I want the user to input something with the cin. So, how can they imput true or false?
Metulburr, I think that might work, I'll give it a try. Thanks. Also, Daleth, I should try that. Seems like the missing piece in my puzzle. Thanks guys.
the advantage is you do not end up with namespace conflicts. I havent yet had a problem in c++, as i havent done much yet in this language, but the same goes for any programming language. You try not to flood the namespace. I have however had problems in Python with it, and it is a nasty bug to find. So from my experience with it in Python, i also moved it over to c++.
So its a general overall good programming practice. If you don't end up doing it, you will after spend hours upon hours looking for a bug that if you did use it, such a bug would not exist.