What am I doing wrong?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 13
Reputation: sosy2001 is an unknown quantity at this point 
Solved Threads: 1
sosy2001 sosy2001 is offline Offline
Newbie Poster

What am I doing wrong?

 
0
  #1
Feb 3rd, 2006
#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;
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: What am I doing wrong?

 
0
  #2
Feb 3rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 13
Reputation: sosy2001 is an unknown quantity at this point 
Solved Threads: 1
sosy2001 sosy2001 is offline Offline
Newbie Poster

Re: What am I doing wrong?

 
0
  #3
Feb 3rd, 2006
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)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: What am I doing wrong?

 
0
  #4
Feb 4th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 13
Reputation: sosy2001 is an unknown quantity at this point 
Solved Threads: 1
sosy2001 sosy2001 is offline Offline
Newbie Poster

Re: What am I doing wrong?

 
0
  #5
Feb 4th, 2006
i dont understand
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: What am I doing wrong?

 
0
  #6
Feb 4th, 2006
Originally Posted by sosy2001
i dont understand
Read your own program. That function has no parameters.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: What am I doing wrong?

 
0
  #7
Feb 4th, 2006
You better read about local variables, glodabl variables, and passing arguments to functions.

Here is a corrected version.
  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>}
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 43
Reputation: Nedals is an unknown quantity at this point 
Solved Threads: 0
Nedals Nedals is offline Offline
Light Poster

Re: What am I doing wrong?

 
0
  #8
Feb 4th, 2006
Originally Posted by sosy2001
i dont understand
Do you know what 'pass a parameter' means?
  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'
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC