Can anyone help me out with this home work ? I'm not being able to figure it out. I'm new to C++
Write a program that uses for statement to calculate the average of several integers. Assume the last value read is the sentinel -1. For example, the sequence 10 8 11 7 23 56 -1 indicates that the program should calculate the average of all the values preceding -1.
Well, I am not going to do your homework for you, I don't like doing that. But I will give you enough help that will practically give you the answer.
I wrote the program you explained, and it worked out fine. Here are a couple tips:
1) Make sure that you put all the numbers you add in parentheses. Like this: int blah = (x + x + x + x + x + x + x) / 7;
Well. That was my only tip, haha. Think about math class, where calculators were not as smart as humans, and you have to help them out a bit by using parentheses. Well, good news. Calculators are just computers. You are at a computer, trying to make it a calculator. I tried it without parentheses, and I didn't get the right answer. Anyway, glad to help!