Sunday, July 12, 2009

Problem with my c++ code concerning functions?

#include %26lt;iostream.h%26gt;





string lab10identification(string labId)


return labId;





char getLetterGrade (int gradeIn) {


if (gradeIn %26gt;= 90 %26amp;%26amp; gradeIn %26lt;=100)


return 'A';


if (gradeIn %26gt;= 80 %26amp;%26amp; gradeIn %26lt;=90)


return 'B';


if (gradeIn %26gt;= 70 %26amp;%26amp; gradeIn %26lt;=80)


return 'C';


if (gradeIn %26gt;= 60 %26amp;%26amp; gradeIn %26lt;=70)


return 'D';


if (gradeIn %26gt;= 0 %26amp;%26amp; gradeIn %26lt;=59)


return 'A';





}





int getNulericGrade(int grade){


return grade;


}





int main() {


int grade;


char letterGrade;


string labId = "lab 10 Ju Kim jhk0042@unt.edu";





lab10identification();





do {


grade = getNumericGrade();


if (grade != -1) {


letterGrade = getLetterGrade(grade);


cout %26lt;%26lt; "The student's letter grade is: " %26lt;%26lt; letterGrade %26lt;%26lt; endl;


}


} while (grade != -1);





cout %26lt;%26lt; "Good-bye" %26lt;%26lt; endl;


return 0;


} // main





This is my code and I can't figure out what is wrong with it. It won't even compile.

Problem with my c++ code concerning functions?
Not sure what you are trying to do with this function, but you are missing your braces:





string lab10identification(string labId)


return labId;





Also when you call it in main, it needs a string argument, I am guessing that is supposed to be 'labld'?





Also, you are giving them an 'A' when the score is between 0 and 59. And after all of those 'if' statements, you need to return something in case none of the 'if' statements are satisfied.





Also, I am guessing that 'getNumericGrade()' should be getting input from the user? Because right now it is doing nothing.





When you say it doesn't compile, you probably need to be more specific to get really good help. Whatever error message you get you should post.





Overall, there are probably a couple more errors that I didn't catch. Instead of writing the whole program at once and hoping there are no errors, you should add little bits at a time and compile at each step to see that your program isn't broken, at least until you get more comfortable programming. It doesn't look like you thought out all of your functions very well... make sure each works before moving onto the next...





Good luck.
Reply:Hi,





where is your





cout %26lt;%26lt; "Please enter student's grade 1-100 type -1 to stop"





I am going to put this in my compiler and get back to you

redbud

No comments:

Post a Comment