Tuesday, July 28, 2009

Could someone check my C++ work?

ok...i have to do a program and i have not completed it yet because as i compiled the program....it gave me 2 errors:





error C2143: syntax error : missing ';' before 'type'





now...i dont know how to fix this, could someone either tell me or show me what i'm doing wrong?





here's WHERE the error is showing in the program








int Calc_Grade(int midterm_exam, int final_exam)


{


double grade;


int rounded_grade;





grade = (MIDTERM_WEIGHT * midterm_exam + FINAL_WEIGHT * final_exam);


rounded_grade = grade + 0.5;





return rounded_grade;


}





i'm not sure what "type" means and how do i fix this error so i can move on in my project...





PLEASE HELP ME...I'M STUCK!!!

Could someone check my C++ work?
wat are MIDTERM_WEIGTH AND FINAL_WEIGHT


are they defined constants


they check how u defined them


u sudnt terminate them with ;





if it dont solve ur prob paste the entire code
Reply:My best guess is that your MIDTERM_WEIGHT or your FINAL_WEIGHT as defined at the top may be your problem...did you define them like this:





#define MIDTERM_WEIGHT 69


#define FINAL_WEIGHT 69





If you add a ";" at the end of those statements then you'd have a problem...You should not have a ";" at the end of them...





To the replier about mixed types...what she did is actually fine in C...C/C++ will just truncate the double to an int...that is unless she changed her Warnings to flag as error in the case of mixed types....it is recommended though that you properly typecast it to an int so your line ideally should read:





rounded_grade = (int) (grade + 0.5);





But like i said, by not explicitly typecasting it to an int you will only get a "warning" from the complier...not an error.
Reply:Not a C++ programmer, VB, but wouldn't your function require a semi-colon after the closing bracket?
Reply:in C++ you cannot mix different types of variables (in this case a double with an int).





so 'type' probably means when you make rounded_grad = grade + 0.5 and that is combining an int with a double.





just try making both of the variables the same type.
Reply:I think you need to put a semi-colon -





int Calc_Grade(int midterm_exam, int final_exam) %26lt;- here


{


double grade;


int rounded_grade;





grade = (MIDTERM_WEIGHT * midterm_exam + FINAL_WEIGHT * final_exam);


rounded_grade = grade + 0.5;





return rounded_grade;
Reply:please im me i have your question to this answer please i will help you on this


No comments:

Post a Comment