This code works, but it is pretty redundant and can be broken by the user if they enter a string for the test scores or something; this is okay since you are just learning however. I would have an if statement that does something like this this:
1 2 3 4 5
|
if(cin.fail())
{
cin.clear();
cin.ignore();
}
|
as for a grading scale, all you did to calculate what letter grade they got was use if greater than or equal to 90, return A. So you could replace 90 with a variable then have the user input those variables at the beginning. you would need 5 variables then you could check if the avg is greater than those and less than the one above it. Say b is equal to 82 and a is equal to 92, you could do:
1 2 3 4 5 6
|
int a = 92;
int b = 82;
if(avg >= a) return 'A';
else if(avg >= b) return 'B';
...
|
I noticed you were using cout twice since you wanted two line spaces when they were entering the test scores, you can just do << endl << endl. and it will give you another space without having to use two couts.
Another thing, in the calcAverage function, you had the return type as a float but made avg a double and casted the answer to a double, then returned a double. You should probably decide which one you want based on how many decimal places you need, there's no point in making all of the math a double and then returning a float. It won't round up or down if you do, or make the math more accurate, it just chops off decimal places and uses more memory than you need.
This was actually a really interesting post for me to read because i made a program exactly like that when I first started learning C++. The biggest problem I had was overthinking things that had simple fixes, i would write like 50 lines to fix something or redo my entire program over something really easy that could have been done in 2 lines.
A few tips:
Once your program is finished, refine it, ask yourself a few questions, "Can the user easily crash my program?" "Does the program do what i want it to do?" "how can i add more useful functionality?"
Google is your friend, when you have problems go searching for solutions, if you have a question, especially just starting out, chances are it's been asked before and has answers. Making posts about your code and asking people to review it like this is good, it will help you improve.
Make programs that challenge you, but aren't so above your head that you could never do them with your current knowledge. Try to make programs that you don't initially know how to make but have an idea, then fill in the gaps as you do it.
Once you get better at C++ you can do a lot of really interesting projects. Hope this was helpful.