User forums > Help

Compile Error

(1/1)

Ragehottie:
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:

--- 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;
}

--- End code ---
And this is the error:

--- Code: ---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

--- End code ---
I have no clue what to do. Halp pl0x. Thnx for reading.

ollydbg:

--- Code: ---/*This program gets the ages of 5 kids and averages them*\
--- End code ---
You have wrong C style comment here.

BTW: Your problem is not related to C::B, and you should ask in some other forums.

Ragehottie:
Oh, ok. Sorry where should I put this?

Radek:
/*This program gets the ages of 5 kids and averages them*\

 ;D

beldaz:
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. Anyway, to put you out of your misery...:


--- Quote from: Ragehottie on December 26, 2011, 05:50:57 am ---
--- Code: ---/*This program gets the ages of 5 kids and averages them*\

--- End code ---

--- End quote ---
should be

--- Code: ---/* This program gets the ages of 5 kids and averages them */

--- End code ---

Also, don't include .h files unless that's what you really want:

--- Code: ---#include <iostream> // not #include <iostream.h>

--- End code ---

Furthermore, some of your stream operations are in the wrong direction

--- Code: ---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 ...

--- End code ---

Finally, it is standard for main() to return an int, so it should start with

--- Code: ---int main () {

--- End code ---
and end with

--- Code: ---return 0;
}

--- End code ---
Returning 0 typically indicates the program ran successfully. Check something like POSIX standards for examples of other return codes.

Navigation

[0] Message Index

Go to full version