This is my first attempt at a programme. Is it good form? Does it follow best practice? Or am I completely off the mark?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
string a;
string b;
string enterName()
{
while (true)
{
cout << "what is your name?: ";
getline(cin, a);
if (a == "")
cout << "Let's try that again." << endl;
if (a != "")
return a;
}
}
string enterAge()
{
while (true)
{
cout << "What is your age " << a << "?: ";
getline(cin, b);
if (b == "")
cout << "You did not answer the question." << endl;
if (b != "")
return b;
}
}
int verifyAge()
{
while (true)
{
int x = atoi(enterAge().c_str());
if (x > 0 && x < 95)
return x;
cout << "That is not possible, put your real age please." << endl;
}
}
string address()
{
while (true)
{
cout << "Where do you live " << a << "?: ";
string c;
getline(cin, c);
if (c == "")
cout << "You must live somewhere." << endl;
if (c != "")
return c;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
system("Color 1A");
string a = enterName();
cout << endl;
int y = verifyAge();
cout << endl;
string c = address();
cout << endl;
system("cls");
cout << endl << endl << endl;
cout << "So your name is " << a << " you are " << y << " years old"
<< " and you live in " << c << endl << endl << endl;
cout << "Press any key to exit";
cin.get();
return 0;
}