-
Help with code?
Hi, i am a total newbie and could you tell me whats wrong with this code?
#include <iostream.h>
#include <string.h>
int main()
{
char name[20];
char vclass[20];
char race[20];
int age[2000];
cout<<"Welcome to quest for the holy pistol!"<<endl;
cout<<"The name of the character: ";
cin.getline(name, 20, '\n');
cout<<"Pick a class: ";
cin.getline(vclass, 20, '\n');
cout<<"Pick a race: ";
cin.getline(race, 20, '\n');
cout<<"Age of the character: ";
cin.getline(age, 2000, '\n');
cout<<"Name:"<<name<<;
cout<<"Class:"<<vclass;
cout<<"Race:"<<race;
cout<<"Age:"<<age;
return 0;
}
-
two things that stand out.
>cin.getline(age, 2000, '\n');
why is this 2000.
>cout<<"Name:"<<name<<;
note the extra ilegal '<<' before the semi colon
tell us what errors your getting, you can't expect us to debug the code for you.
-
>>cin.getline(age, 2000, '\n');<<
Also, no need for this or int age[2000]; for that matter.
Just
Code:
int age;
and
cin>>age;
shall suffice
-
Finally i got it to work... i dont quite remember the error but at least i got it fixed. I am such a newbie!
#include <iostream.h>
#include <string.h>
int main()
{
char name[20];
char vclass[20];
char race[20];
int age;
cout<<"Welcome to quest for the holy pistol!"<<endl;
cout<<"The name of the character: ";
cin.getline(name, 20);
cout<<"Pick a class: ";
cin.getline(vclass, 20);
cout<<"Pick a race: ";
cin.getline(race, 20);
cout<<"Age of the character: ";
cin>>age;
cout<<"Name:"<<name<<endl;
cout<<"Class:"<<vclass<<endl;
cout<<"Race:"<<race<<endl;
cout<<"Age:"<<age<<endl;
return 0;
}