954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What am I doing wrong?

#include

using namespace std;


// This program takes the numerical score and outputs a letter grade.//

int getScore ()
{


int count;
int score,



for (count = 0; count <10; count ++){
cout << "\nEnter the student's score: "<< endl;
cin >> score

}


cout <<"\nThe score is/are: " << score << endl;
return 0 ;
}

int printGrade()

{


int grade =0;


if ( grade >= 90)
cout <<"\nYour grade is A." << endl;
else
if (grade >= 80 )
cout <<"\nYour grade is B." << endl;
else
if (grade >= 70 )
cout <<"\nYour grade is C." << endl;
else
if (grade >= 60 )
cout <<"\nYour grade is D." << endl;
else
cout <<"\nYour grade is F." << endl;


return 0;

}

int main ()
{

getScore();
printGrade();
int num = getScore ();

cout << printGrade(num);

return 0;
}

sosy2001
Newbie Poster
13 posts since Jan 2006
Reputation Points: 10
Solved Threads: 1
 

what errors are you getting? I see a couple of missing semicolons -- your compiler should complain about them. Look at the errors, then look at your code and see if you can figure out what's wrong.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This is the error i'm getting


Compiling...
printGrade.cpp
C:\Documents and Settings\Administrator\My Documents\printGrade.cpp(68) : error C2660: 'printGrade' : function does not take 1 parameters
Error executing cl.exe.

printGrade.obj - 1 error(s), 0 warning(s)

sosy2001
Newbie Poster
13 posts since Jan 2006
Reputation Points: 10
Solved Threads: 1
 

That error means the program is attempting to pass the wrong number of parameters. how many parameters to you see in that function? It doesn't have any parameters, yet your program is attempting to pass one parameter -- they have to be consistent.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

i dont understand

sosy2001
Newbie Poster
13 posts since Jan 2006
Reputation Points: 10
Solved Threads: 1
 
i dont understand

Read your own program. That function has no parameters.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

You better read about local variables, glodabl variables, and passing arguments to functions.

Here is a corrected version.

#include <iostream>
using namespace std;
// This program takes the numerical score and outputs a letter grade.//
int getScore ()
{[INDENT]int count;
int score,

cout << "\nEnter the student's score: "<< endl;
cin >> score
cout <<"\nThe score is/are: " << score << endl;
return score;[/INDENT]}



int printGrade( int grade)
{[INDENT]if ( grade >= 90)[INDENT]cout <<"\nYour grade is A." << endl;[/INDENT]else if (grade >= 80 )[INDENT]cout <<"\nYour grade is B." << endl;[/INDENT]else if (grade >= 70 )[INDENT]cout <<"\nYour grade is C." << endl;[/INDENT]else if (grade >= 60 )[INDENT]cout <<"\nYour grade is D." << endl;[/INDENT]else[INDENT]cout <<"\nYour grade is F." << endl;[/INDENT]return 0;[/INDENT]}

int main ()
{[INDENT]for ( int i = 0 ; i < 10 ; i++ )
{[INDENT]int num = getScore ();
printGrade(num);[/INDENT]}
return 0;[/INDENT]}
WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 
i dont understand


Do you know what 'pass a parameter' means?

//If you have this function...
int printGrade(int grade) {
  if ( grade >= 90) {
     ...
  }
}

// 'grade' is a parameter that is passed into the function.

int main () {
  ...
  printGrade(23);
  ...
}

// Here the value 23 is passed into the function 'printGrade'
// using the variable 'grade'
Nedals
Light Poster
43 posts since Dec 2005
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You