#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
//This Part of The Code will ask user his data for later use
int main (int nNumberofArgs, char* pszArgs[])
{
int nYear;
int nName;
cout << "Please Enter your last name: ";
cin >> nName;
cout << "Please Enter a number between 2300 - 3000: ";
cin >> nYear;
//This Part of the code explains the storyline to the user
cout << "Hello Major " << nName << "It is Year " << nYear <<
cout << "Lt.Kowalski : Sir what the ship is talking damage from the morgs what should we do?";
system ("PAUSE");
return 0;
}
#include <iostream>
#include <cstdlib>
usingnamespace std;
//This Part of The Code will ask user his data for later use
int main (int nNumberofArgs, char* pszArgs[])
{
char nName[20];
int nYear;
cout << "Please Enter your last name: ";
cin >> nName;
cout << "Please Enter a number between 2300 - 3000: ";
cin >> nYear; //but this will cause an error if user enter alphabet number
//This Part of the code explains the storyline to the user
system("cls");
cout << "Hello Major " << nName <<endl<<"It is Year " << nYear<<endl;
cout << "Lt.Kowalski : Sir what the ship is talking damage from the morgs";
cout <<endl<< "what should we do?";
cout<<endl<<endl;
system ("PAUSE");
return 0;
}
but cin<<nYear will goes wrong if user hit alphabet number soo you need to check input from user, i use this to check
#include <iostream>
#include <cstdlib>
#include <sstream>
usingnamespace std;
bool check_digit(char string[])
{
if(strlen(string)>0)
{
cout<<endl<<"----------start checking---------------"<<endl;
for(int i=0;i<strlen(string);i++)
{
if(!isdigit(string[i]))
{
cout<<endl<<"dont use Alphabet on it"<<endl;
returnfalse;
}
}
}
else
{
cout<<endl<<"dont use Alphabet on it";
returnfalse;
}
returntrue;
}
//This Part of The Code will ask user his data for later use
int main (int nNumberofArgs, char* pszArgs[])
{
char nName[20],charyear[6];
int nYear;
cout << "Please Enter your last name: ";
cin >> nName;
do
{
cout << "Please Enter a number between 2300 - 3000: ";
cin >> charyear;
}while(!check_digit(charyear));
stringstream(charyear)>>nYear; //convert from char to int;
//This Part of the code explains the storyline to the user
system("cls");
cout << "Hello Major " << nName <<endl<<"It is Year " << nYear<<endl;
cout << "Lt.Kowalski : Sir what the ship is talking damage from the morgs";
cout <<endl<< "what should we do?";
cout<<endl<<endl;
system ("PAUSE");
return 0;
}