First posts are always the greatest.
Anyway, I'm trying to make a simple program in C++ that basically just stores information until close, such as name, age, and eventually other personal preferences that will just basically test the knowledge that I've gathered so far and for me to get used to it if I want to be a game programmer.
I'm using Dev-C++ 4.9.9.2 as my compiler. This is what I have:
Code:
#include <iostream>
using namespace std;
int main()
{
char name[256];
int age;
int confirm;
cout<<"Hey there.\n ";
do
{
cout<<"What is your name? ";
cin.getline (name, 256, '\n');
}
while (confirm==0);
cout<<"\n"<<name<<" is your name? \n\n Press 1 to confirm \n\n Press 2 to change \n\n", name;
cin>> confirm;
if (confirm==1)
{
cout<<"\nGot it.\nAnd how old are you? ";
cin>> age;
cout<<"\nSo you're "<<age<<"? Alright, thanks.\n\n ";
}
if (confirm==2)
{
cout<<"\nOh. Well then...\n";
confirm=0;
cout<<"Comfirm = "<<confirm<<""; //Just to prove that the variable sets back to 0, so it SHOULD loop.
}
cin.ignore(); //These are just here because, well, they are. I'm not exactly most efficient yet.
cin.ignore();
cin.get();
return 0;
}
This is my theory: It'll ask for your name, and you say 1 or 2. If you say 1, it continues. Great. But if you say 2, I want it to go back and give you a chance to re-enter the name, since it sets confirm back to 0, and the loop is to be done while confirm equals 0.
The issue? It never goes back to the loop.
Please help me fix this issue. You don't necessarily need to rewrite anything, just point me in the right direction.