Saturday, May 22, 2010

What is wrong with my c++ program concerning functions?

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





string lab10identification(string labId){


// too few arguments?


cin %26gt;%26gt; 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 'F';


}


int getNulericGrade(int grade){


cout %26lt;%26lt; "Enter a grade from -1 to 100 (-1 to stop) ";


cin %26gt;%26gt; grade;


return grade;


}


int main() {


int grade;


char letterGrade;


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





lab10identification(); // error:at this point





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;


}

What is wrong with my c++ program concerning functions?
well of course you are gonna get an error,


you are calling a function that takes one parameter and you are passing none!





lab10idenfication( INSERT_STRING_VARIABLE_HERE)


also...that function RETURNS a value (of type string) (which by the way I don't see included anywhere..so you might wanna add using namespace std; at the top of your code)..and since it returns something, you might wanna store it somewhere








insertStringToStoreHere = lab10idenfication( INSERT_STRING_VARIABLE_HERE)








but actually you could just simply do something like this


string lab10identification()


{


string labld


cin %26gt;%26gt; labId;


return labId;


/* so you wouldnt need to pass anything */


}





or something like





string lab10identification(string %26amp;str)


{


cin %26gt;%26gt; labId;


/*you would have to pass a string when calling it*/


}





in which case is easier just to put that line into the main function...but oh well..it's up to you





and the other error, is for the same reason..i didn't look at what that function does...but that should get you going
Reply:string labId = "lab 10 Jkim jhk0042@unt.edu";





lab10identification(labId); // error:at this point


No comments:

Post a Comment