| | |
What am I doing wrong?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2006
Posts: 13
Reputation:
Solved Threads: 1
#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;
}
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;
}
You better read about local variables, glodabl variables, and passing arguments to functions.
Here is a corrected version.
Here is a corrected version.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; // This program takes the numerical score and outputs a letter grade.// int getScore () {<blockquote>int count; int score, cout << "\nEnter the student's score: "<< endl; cin >> score cout <<"\nThe score is/are: " << score << endl; return score;</blockquote>} int printGrade( int grade) {<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>} int main () {<blockquote>for ( int i = 0 ; i < 10 ; i++ ) {<blockquote>int num = getScore (); printGrade(num);</blockquote>} return 0;</blockquote>}
バルサミコ酢やっぱいらへんで
•
•
Join Date: Dec 2005
Posts: 43
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by sosy2001
i dont understand
C++ Syntax (Toggle Plain Text)
//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'
![]() |
Similar Threads
- My CD-RW plays but won't burn. What could be wrong?? Help Please? (Storage)
- Retrieve email I sent to the wrong person (Web Browsers)
- Ram voltage wrong?? (Motherboards, CPUs and RAM)
- Am I going about this the wrong way (IT Professionals' Lounge)
- wats wrong with imesh??? (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Building a Shell. I'm in Hell
- Next Thread: Strings
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






