Author Topic: Compile Error  (Read 7880 times)

Offline Ragehottie

  • Single posting newcomer
  • *
  • Posts: 2
Compile Error
« on: December 26, 2011, 05:50:57 am »
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;
}
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
I have no clue what to do. Halp pl0x. Thnx for reading.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Compile Error
« Reply #1 on: December 26, 2011, 06:32:17 am »
Code
/*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.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Ragehottie

  • Single posting newcomer
  • *
  • Posts: 2
Re: Compile Error
« Reply #2 on: December 26, 2011, 06:40:05 am »
Oh, ok. Sorry where should I put this?

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: Compile Error
« Reply #3 on: December 26, 2011, 07:09:32 am »
/*This program gets the ages of 5 kids and averages them*\

 ;D

Offline beldaz

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Compile Error
« Reply #4 on: December 26, 2011, 12:33:51 pm »
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...:

Code
/*This program gets the ages of 5 kids and averages them*\
should be
Code
/* This program gets the ages of 5 kids and averages them */

Also, don't include .h files unless that's what you really want:
Code
#include <iostream> // not #include <iostream.h>

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

Finally, it is standard for main() to return an int, so it should start with
Code
int main () {
and end with
Code
return 0;
}
Returning 0 typically indicates the program ran successfully. Check something like POSIX standards for examples of other return codes.