This semester has been brutal! You’ve had five classes, three of which are required for your major and two electives that turned out to be tougher than you anticipated. Yet, you pulled through the term without dropping a single course. You now have your grades and want to know your GPA for the semester.
This month’s Exercise is an input and math puzzle. Your job is to write code that prompts for grades from five courses. The range of input is from 0 through 100.
For grades 90 to 100, a value of 4.0 is assigned. For grades 80 to 89, assign 3.0. For grades 70 to 79 assign 2.0. For grades 60 to 69 assign 1.0. For grades below 60, assign zero.
After obtaining each course’s grade, your program calculates and outputs the GPA based on the average grade. Here’s a sample run:
Enter grade (0 to 100) for class #1: 99
Enter grade (0 to 100) for class #2: 81
Enter grade (0 to 100) for class #3: 92
Enter grade (0 to 100) for class #4: 66
Enter grade (0 to 100) for class #5: 74
Your semester GPA is 2.8
Ensure that you validate input, checking not only for grades within the proper range but to ensure that numeric values were input and not strings or other weird stuff.
Try this Exercise on your own before you peek at my solution.