| | |
c++ Grade program
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2005
Posts: 4
Reputation:
Solved Threads: 0
I need help with this program. here is what we are supposed to do.
The program should prompt the user to 'Please enter numeric grade: '.
The program will then pass the numeric grade to a function that will convert to a letter grade. This function should have the following prototype:
char get_letter_grade (int grade_num);
100-90 A
89-80 B
79-70 C
69-60 D
below 60 F
4. The character that is returned will then be sent to a function to determine if the letter grade is passing (grades higher than 59 are passing). This function should have the following prototype:
bool is_passing(char grade_letter);
5. Your program should then display the results. For example:
Please enter numeric grade: 83
The letter grade is: B.
The grade is passing.
Here is what i have so far.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int grade_num;
cout<< "Please enter numeric grade:"<< endl;
cin>> grade_num;
return 0;
}
char get_letter_grade (int grade_num)
{
if (grade_num<=60);
cout<< "The letter grade is F"<< endl;
else if ( grade_num<=69);
cout<< "The letter grade is D"<< endl;
else if (grade_num<=79);
cout<< "The letter grade is C"<< endl;
else if (grade_num<=89);
cout<< "The letter grade is B"<< endl;
else (grade_num<=100);
cout<< "The letter grade is A"<< endl;
return (grade_num);
}
bool is_passing(char grade_letter)
{
The program should prompt the user to 'Please enter numeric grade: '.
The program will then pass the numeric grade to a function that will convert to a letter grade. This function should have the following prototype:
char get_letter_grade (int grade_num);
100-90 A
89-80 B
79-70 C
69-60 D
below 60 F
4. The character that is returned will then be sent to a function to determine if the letter grade is passing (grades higher than 59 are passing). This function should have the following prototype:
bool is_passing(char grade_letter);
5. Your program should then display the results. For example:
Please enter numeric grade: 83
The letter grade is: B.
The grade is passing.
Here is what i have so far.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int grade_num;
cout<< "Please enter numeric grade:"<< endl;
cin>> grade_num;
return 0;
}
char get_letter_grade (int grade_num)
{
if (grade_num<=60);
cout<< "The letter grade is F"<< endl;
else if ( grade_num<=69);
cout<< "The letter grade is D"<< endl;
else if (grade_num<=79);
cout<< "The letter grade is C"<< endl;
else if (grade_num<=89);
cout<< "The letter grade is B"<< endl;
else (grade_num<=100);
cout<< "The letter grade is A"<< endl;
return (grade_num);
}
bool is_passing(char grade_letter)
{
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
Please use code tags
Remeber you are working with a specific range so you are going to need to use the && in your get letter grade function. Also that function needs some other adjustments. You also need to call it from main. Did you even go to class?
Remeber you are working with a specific range so you are going to need to use the && in your get letter grade function. Also that function needs some other adjustments. You also need to call it from main. Did you even go to class?
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
This solution won't work for you, but it should give you a push in the right direction:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; char letter_grade(int grade_num) { char limit[][4] = {90,80,70,60,'A','B','C','D'}; for (int i = 0; i < 4; i++) { if (grade_num >= limit[0][i]) return limit[1][i]; } return 'F'; } bool is_passing(char grade_letter) { return grade_letter < 'F'; // Portability is for wusses } int main() { for (int i = 0; i < 101; i++) { cout<< i <<" = "<< letter_grade(i) <<": "; cout<< boolalpha << is_passing(letter_grade(i)) <<endl; } }
New members chased away this month: 5
I'd like to point out that these solutions are no better or worse than anyone elses, but rather a demonstration of different ways to solve the problem and still get the same result.
or Needs tweeking if grade is 100 or less then 60
C++ Syntax (Toggle Plain Text)
char get_letter_grade (int grade_num) { char Result; switch (grade_num / 10) { case 10: case 9: Result = 'A'; break; case 8: Result = 'B'; break; case 7: Result = 'C'; break; case 6: Result = 'D'; break; default: Result = 'F'; } return Result; }
or Needs tweeking if grade is 100 or less then 60
C++ Syntax (Toggle Plain Text)
char get_letter_grade (int grade_num) { return ((10 - (Grade / 10)) + 64); }
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by sutty8303
Thanks for all of the help. We get little to no help from the TA's in our classes and yes i do go to class, it's hard to learn when they do not teach what you need to know.
int grade;
grade = 0;
cout << "Enter grade: ";
cin >> grade;
{
if (grade >= 90)
cout << "A";
else if (grade >= 80)
cout << "B";
else if (grade >=70)
cout << "C";
else if (grade >= 60)
cout << "D";
else
cout << "F";
}
return 0;
}
i don't know if that will work, its been way to long since writing code
>i don't know if that will work
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.
To this day, I still test my code before posting it 9 times out of 10. I'm confident that it's flawless (though part of that is ego), but I still would rather double and triple check myself than have somebody else correct a stupid mistake.
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.
To this day, I still test my code before posting it 9 times out of 10. I'm confident that it's flawless (though part of that is ego), but I still would rather double and triple check myself than have somebody else correct a stupid mistake.
New members chased away this month: 5
![]() |
Similar Threads
- student grade program [help!] (C++)
- Grade book program using arrays and Bubble sort (C++)
- C++ Student Average Grade program (C++)
- Grade Program print name, grade (C++)
- Grade Program (C++)
- grade prediction program (C)
Other Threads in the C++ Forum
- Previous Thread: Main Options / Style Questions
- Next Thread: Function Error Message Help
Views: 11654 | Replies: 18
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






