compile error

I can't get this to compile. Please Help..

#include <iostream>
using namespace std;
int main()
{
const int Size = 20;
char FirstName[Size];
char LastName[Size];
char Grade[Size];
int Age[Size];

cout << "What is your first name? ";
cin.getline(FirstName, Size);
cout << FirstName << "\n";

cout << "What is your last name? ";
cin.getline(LastName, Size);
cout << LastName << "\n";

cout << "What letter grade do you deserve? ";
cin.getline(Grade, Size);
cout << Grade << "\n";

cout << "What is your age? ";
cin.getline(Age, Size);
cout << Age << "\n";

cout << "Name:" << LastName << "," << FirstName << "\n";
cout << "Grade:" << Grade << "\n";
cout << "Age:" << Age << "\n";

return 0;

}
Last edited on
you declared "Age" as an array, try changing that
thanks, I changed the Age array to "int age;" and made the necessary adjustments in the rest of the program..


The program compiles now. But when I enter the "first name", it is outputted once directly to the right of the first string output, and it automatically outputs again on the very next line, before asking the second question... It's the same way with all the questions...


Example:

What is your first name? Abe Steven
Abe Steven
What is your last name? Froman
Froman
What letter grade do you deserve? A
A
What is your age? 33
33

...


Here is the program now...


#include <iostream>
using namespace std;
int main()
{
const char Size = 20;
char FirstName[Size];
char LastName[Size];
char Grade[Size];
int age;



cout << "What is your first name? ";
cin.getline(FirstName, Size);
cout << FirstName << "\n";

cout << "What is your last name? ";
cin.getline(LastName, Size);
cout << LastName << "\n";

cout << "What letter grade do you deserve? ";
cin.getline(Grade, Size);
cout << Grade << "\n";

cout << "What is your age? ";
cin >> age;
cout << age << "\n";

cout << "Name:" << LastName << "," << FirstName << "\n";
cout << "Grade:" << Grade << "\n";
cout << "Age:" << age << "\n";

return 0;


}
Last edited on
The programme is doing what you asked it to.

Try removing the cout << FirstName << "\n" right before the cin.getline() call.
That should solve it, if that is what you wanted.
Last edited on
yes, that works...

heh, your right.. The program WAS doing what I told it to do... I just barely started programming :)



thanks
Last edited on
Topic archived. No new replies allowed.