hi guys, i must right this program in c++ as 50% of my final grade and i have no clue how to do it because im a math major and im required to take this course is there anyone who can help me with this real quick pleaseeeee


//* Write a C++ program that allows a person to keep entering *
//* numbers. When the user enters the value 999, the average of *
//* the numbers (except 999) will be displayed to the nearest *
//* tenth. *
//* *
//* EXAMPLE: If the user entered the #'s: 90,78,82,and 999 *
//* the output would be *
//* AVERAGE = 250/3 = 83.3

Please email me *not-allowed*@daniweb

thanx

Hello,

First, please do not post programming assistance questions in the Linux Tutorials area. That location is for sample codes and how-to articles, not requests.

Second, we do not allow emailing off-group of answers / solutions. Such a practice destroys a community, as the email will help you, yet it will not help the next guy.

And third, members of the community do not do homework for you as a rule. They help correct things, and inspire ideas, but do not do the work for you. They are going to want to see your efforts on the coding. If I were you, I would post it while you still have time.

Christian

Being a math major, you probably don't need to be told that the average will be the sum divided by the count.
[Heavy hinting for possible variable names here.]

Entering a single number might be done like this.

int  number;
      cout << "Enter a number: ";
      cin  >> number;

Checking to see whether the number is 999 ought not be too difficult -- but what to do if this value is entered?

Well it's quite likely that you'd want the code for entering a number in a loop. So when this sentinel number is reached, perhaps you would want to break out of the loop. If it wasn't this sentinel value, then I suppose you'd want to add it to the sum (which was most likely initialized to zero before the loop was entered).

If you had been adding one to your count (which was most likely initialized to zero before the loop was entered) each time through the loop, then it wouldn't be too difficult to find the average.

I won't write it in executable code, but this would be how to break out of the loop when 999 is entered.

while exit is not one{
   input number
   if number is not 999 sum=sum+number else exit=1
}

This way, at the end of the "while" loop, it would return to check if "exit" equals 1 or not. By default, it will equal 0, and will not change to 1 unless 999 is input.

Once "exit" equals 1 the code will go on. If you actually want 999 to be added to the sum, however, you could do this:

while exit is not one{
   input number
   if number is not 999 sum=sum+number else exit=1
   if exit=1 {
      output "Do you want to average the numbers now? (1=yes, 2=no)"
      input choice
      if choice=2 {sum=sum+999; exit=0}
   }
}

That way, if you enter 2, 999 will be added to the sum, and "exit" will be reverted to 0 before it is checked again.

Hope this helped.

This article has been dead for over six months. Start a new discussion instead.