Now that you know conditionals, let's build a program that converts numeric scores into letter grades!
YOUR TASK
Create a program that:
Asks the user for a score (0-100)
Determines the letter grade based on the score
Displays the letter grade with a special message
Handles invalid input (scores outside 0-100)
Grading Scale:
90-100: Grade A - "Excellent work!"
80-89: Grade B - "Great job!"
70-79: Grade C - "Good effort!"
60-69: Grade D - "You passed, but keep studying!"
0-59: Grade F - "Need improvement. Don't give up!"
Hint 1: Basic Structure
Start with these steps:
1. Declare an int score; variable
2. Use cout to ask for the score
3. Use cin >> score; to get input
4. First check if score is valid (0-100)
5. Then use if-else statements for grading
Hint 2: If-Else Logic
Conditional structure:
• Check from highest to lowest grade
• if (score >= 90) { ... }
• else if (score >= 80) { ... }
• else if (score >= 70) { ... }
• Continue for D and F
• Don't forget to validate input first!
Hint 3: Full Solution Structure
Complete outline:
1. Get the score from user
2. Check if score < 0 OR score > 100
→ Display "Invalid score"
3. Otherwise, check ranges:
→ if score >= 90: "Grade: A - Excellent work!"
→ else if score >= 80: "Grade: B - Great job!"
→ And so on...
Test Cases
Input: 95 → Output: Grade: A - Excellent work!
Input: 82 → Output: Grade: B - Great job!
Input: 75 → Output: Grade: C - Good effort!
Input: 65 → Output: Grade: D - You passed, but keep studying!
Input: 45 → Output: Grade: F - Need improvement. Don't give up!
Example Run (score = 95):
Enter your score (0-100): 95
Grade: A - Excellent work!
Code Editor
Ready
Output
Console
Console initialized...
Ready for Practice Project 2: Grade Calculator
> Test your code with different scores
> Use the "Check My Code" button to validate
> Complete all test cases to unlock the Complete button!