A clever person solves a problem. A wise person avoids it.
- Einstein
News
Site News
Latest Comments
Affiliates
Proxies
Contribute!
Chat
Tutorials
Newest Articles
Most Popular
Highest Rated
Latest Comments
Code Samples
Newest Code
Most Popular
Highest Rated
Latest Comments
Blogs
Admins Blog
Newest Blogs
Most Popular
Highest Rated
Latest Comments
Forums
Latest Posts
Latest Topics
Memberlist
[login]
|
[Register]
Grade
by: bs0d
Description:
Visual C++ source code that uses if and else if's to calculate a students grade based on test scores entered.
Code:
//Displays a student's grade #include
using namespace std; //function prototypes int getPointsEarned(); char assignGrade(int); int main() { //declare variables int totalEarned = 0; char grade = ' '; //get total points earned totalEarned = getPointsEarned(); //assign grade grade = assignGrade(totalEarned); //display grade cout << "Grade: " << grade << endl; return 0; } //end of main function //*****program-defined functions***** int getPointsEarned() { //get and accumulate the score, then return the total int score = 0; int total = 0; cout << "Enter the first score: "; cin >> score; while ( score >= 0) { total = total + score; cout << "Enter the next score: "; cin >> score; } // end while loop. return total; } //end of getPointsEarned function. char assignGrade(int points) { //assigns the letter grade char letterGrade = ' '; if (points >= 360) letterGrade = 'A'; else if (points >= 320) letterGrade = 'B'; else if (points >= 280) letterGrade = 'C'; else if (points >= 240) letterGrade = 'D'; else letterGrade = 'F'; //end ifs return letterGrade; } //end of assignGrade function
No Comments for this page.
You Must be
signed in
or a
member
to comment.
Code Stats
11,273
Views
0
Total Comments
0
Rating of 5 (
1
Votes)
Code Options
·
Login to Rate This Code
·
Login to Post a Comment
·
Read more by this author
Related
·
Open and Write System Call
·
Bit Multiplication
·
Hello World
·
Gross Pay
·
Fat Percentage
·
Commission
"AllSyntax.com" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy