Hello guys, I have been working on this all weekend.
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program:
● calcAverage—This function should accept five test scores as arguments and return the average of the scores.
Score Letter Grade
90–100 A
80–89 B
70–79 C
60–69 D
Below 60 F
and where do I put this system pause?
thanks for your help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <cstdlib>
usingnamespace std;
float calcAverage(int s1, int s2, int s3, int s4, int s5)
{
//Fill in code
float averageScore, sum;
sum = (s1 + s2 + s3 + s4 + s5);
averageScore = sum / 5;
return averageScore;
}// end of function calcAverage
how many errors does your code generate?
I dnt get the semantics of what you have written.....I have the solution but i need to understand wat your errors are and your semantics...and system pause...why??
as far as i understand it. you want to make a program that takes 5 inputs and then gives them a grade.
so i have tried to solve it for you and give you something to compare to.
i have written it fast and as easy as i could think off so there may be some bugs. have a look what i have made and try to understand it. and most important try things you like and experiment with it.
most of the code i have use is explained in the tutorials on this website and forum.
feel free to ask questions and use any code i just posted.
i hope this helps you with your problem.
also i dont understand the system pause. i use getch() to keep the cmd open to look at the results and when pressed enter or any other key (i think) the cmd closes.
sainsay
this is the output:
20
60
70
80
90
the average is: 64
20 equals grade F
60 equals grade D
70 equals grade C
80 equals grade B
90 equals grade A
@Nathan2222: thanks for pointing out the mistakes i make. i am still a beginner a programing and C++ is only my second language. and my first, java, i have have not mastered. not even close to be really good at it.
1) global variables, i know it is not really smart to use them but i also tried to keep it more or less simple for people who have less knowledge and using functions that have some parameters might not be as easy to understand in my opinion. ( and i am kinda lazy )
2) int is can also be used for main can it? could you give me a example on how you would do it?
3) conio.h is used for getch() i don't know an easy way to make it different in my coding.
Why is it that you dont have to declare your functions? Because they are above main()?
That feels strange for me. Because Java is very flexible with "public static void main ()."
I did not know that you could use arrays in this way. I will have a go tomorrow trying out the code that is newish to me. Everything else is understandable.
@jamerack: i know that. Why do you think i commented ". . . but i never use it". But i don't see any one line alternative to system ("cls") (hopefully it isn't in Qt).
@sainsay: it's a personal choice. Sometimes i create functions like you did (if a previous function uses the next function) or i do it like i did.
Glad you understood it and i actually learnt something from your code :).
For your problem, when I looked at the example, it didn't look as though it needed a board, and all you had to do was say that the piece moved forward.
It is a minor price to pay for not bogging down the system. I don't feel there is a need to mention how each system uses a different command for it. If you are using it for personal fun programming than it is fine, but if it is for commercial use, it is a big no-no. Either way, there will rarely be a time when C++ is used for GUI.
I work on one system and no bogging down has occurred. Your method may bog the user down. Besides, it's a console thing. It's not like i have the slightest like for it. I'll soon move to Qt and start building gui apps. By then, i won't have to worry about std::cin, std::cout and the system("").
Maya, blender, luxrender etc. use Qt for their gui. Some game engines use C++ for their gui so C++ isn't rarely used.