I have been trying to compile my c++ scripts for 2 weeks, and never found a compile that I could get to work. I got the closet with codeblocks though. Anyways, sorry for the life story. I keep getting an error with this code:
/*This program gets the ages of 5 kids and averages them*\
#include <iostream.h>
main ()
{
int age1, age2, age3, age4, age5;
int Totalage, AverageAge;
//Gets the user's inputs
cout << "First student's age:";
cin >> age1;
cout << "Second stufent's age:";
cin >> age2;
cout >> "Third student's age:";
cin >> age3;
cout >> "Fourth student's age:";
cin >> age4;
cout >> "Fifth student's age:";
cin >> age5;
//adds the total ages
Totalage = age1 + age2 + age3 + age4 + age5;
//divides by five to find the average
AverageAge = Totalage / 5;
//displays the average age
cout >> "The average age of all five students is:" << AverageAge;
}
And this is the error:
Compiling: C:\Users\***\Desktop\MyFirstProgram.c
C:\Users\***\Desktop\MyFirstProgram.c:1:1: error: unterminated comment
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings
I have no clue what to do. Halp pl0x. Thnx for reading.
/*This program gets the ages of 5 kids and averages them*\
You have wrong C style comment here.
BTW: Your problem is not related to C::B, and you should ask in some other forums.
Ouch, you're really stuck with some basic mistakes. You should try simple things one at a time rather than doing so much. As others have said, the problem isn't the compiler, it's your code, so you should be posting on a more appropriate forum such as this newbie forum (http://www.cplusplus.com/forum/beginner/). Anyway, to put you out of your misery...:
/*This program gets the ages of 5 kids and averages them*\
should be
/* This program gets the ages of 5 kids and averages them */
Also, don't include .h files unless that's what you really want:
#include <iostream> // not #include <iostream.h>
Furthermore, some of your stream operations are in the wrong direction
cout << "First student's age:";
cin >> age1;
cout << "Second student's age:";
cin >> age2;
cout << "Third student's age:"; // not cout >> "Third student's age:";
cin >> age3;
cout << "Fourth student's age:"; // not cout >> "Fourth student's age:";
cin >> age4;
cout << "Fifth student's age:"; // not cout >> "Fifth student's age:
cin >> age5;
[...]
cout << "The average age of all five students is:" << AverageAge; // not cout >> "The average age ...
Finally, it is standard for main() to return an int, so it should start with
and end with
Returning 0 typically indicates the program ran successfully. Check something like POSIX standards for examples of other return codes.