944,123 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1502
  • C++ RSS
Feb 3rd, 2006
0

What am I doing wrong?

Expand Post »
#include <iostream>

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;
}
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sosy2001 is offline Offline
13 posts
since Jan 2006
Feb 3rd, 2006
0

Re: What am I doing wrong?

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Feb 3rd, 2006
0

Re: What am I doing wrong?

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)
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sosy2001 is offline Offline
13 posts
since Jan 2006
Feb 4th, 2006
0

Re: What am I doing wrong?

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Feb 4th, 2006
0

Re: What am I doing wrong?

i dont understand
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sosy2001 is offline Offline
13 posts
since Jan 2006
Feb 4th, 2006
0

Re: What am I doing wrong?

Quote originally posted by sosy2001 ...
i dont understand
Read your own program. That function has no parameters.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Feb 4th, 2006
0

Re: What am I doing wrong?

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

Here is a corrected version.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. // This program takes the numerical score and outputs a letter grade.//
  4. int getScore ()
  5. {<blockquote>int count;
  6. int score,
  7.  
  8. cout << "\nEnter the student's score: "<< endl;
  9. cin >> score
  10. cout <<"\nThe score is/are: " << score << endl;
  11. return score;</blockquote>}
  12.  
  13.  
  14.  
  15. int printGrade( int grade)
  16. {<blockquote>if ( grade >= 90)<blockquote>cout <<"\nYour grade is A." << endl;</blockquote>else if (grade >= 80 )<blockquote>cout <<"\nYour grade is B." << endl;</blockquote>else if (grade >= 70 )<blockquote>cout <<"\nYour grade is C." << endl;</blockquote>else if (grade >= 60 )<blockquote>cout <<"\nYour grade is D." << endl;</blockquote>else<blockquote>cout <<"\nYour grade is F." << endl;</blockquote>return 0;</blockquote>}
  17.  
  18. int main ()
  19. {<blockquote>for ( int i = 0 ; i < 10 ; i++ )
  20. {<blockquote>int num = getScore ();
  21. printGrade(num);</blockquote>}
  22. return 0;</blockquote>}
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Feb 4th, 2006
0

Re: What am I doing wrong?

Quote originally posted by sosy2001 ...
i dont understand
Do you know what 'pass a parameter' means?
C++ Syntax (Toggle Plain Text)
  1. //If you have this function...
  2. int printGrade(int grade) {
  3. if ( grade >= 90) {
  4. ...
  5. }
  6. }
  7.  
  8. // 'grade' is a parameter that is passed into the function.
  9.  
  10. int main () {
  11. ...
  12. printGrade(23);
  13. ...
  14. }
  15.  
  16. // Here the value 23 is passed into the function 'printGrade'
  17. // using the variable 'grade'
Reputation Points: 11
Solved Threads: 0
Light Poster
Nedals is offline Offline
43 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Building a Shell. I'm in Hell
Next Thread in C++ Forum Timeline: Strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC