requesting c++ programmign help for project

aceofskies05

Senior member
Jun 13, 2006
630
0
0
I am currently a senior taking a c++ online class, working out of textbook. I am stuck on this one project and I am seeking help on it.

so here is the project

"write a program that asks the user for a series of integers one at a time. When the user enters the integer 0, the program displays the following info.:
-the number of integers in the series ( not including 0)
- average of the integers
-largest integer in the series
-smallest in the series
- difference between the largest and smallest."

heres what I got so far

"
#include<iostream.h>

main()
{
int number, average, largest, smallest, difference = 0;
int i;
do
{
cout << " enter a number";
cin >> i;
if (i == 0)
{
cout << "The number of integers in the series" << number << endl;
cout << "The average of the integers" << average << endl;
cout << "The largest integer in the series" << largest << endl;
cout << "The smallest integer in the series" << smallest << endl;
cout << "The difference between the largest and smallest integer in the series" << differece << endl;
{break;}
}
}
while (1);
system("pause");
return 0;
"

Thank you for your help
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Your loop seems mostly fine, but you're obviously missing some pieces. Within your current loop consider how you are going to retain the series of ints entered by the user so that you can do the calculations at the end. If you want to come up with some ideas of how to do that and post them, we can give you some feedback.

Once you have all the entered integers retained in some data structure, and the user enters 0, now you have to perform some steps to fill in the values for your placeholder variables. You can pass the entered data to functions that return the proper value, or write the code in your main loop.

Rather than using "pause" to hold the output on screen, consider display a prompt and reading a line.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,364
4,068
75
Assume you have a set of numbers written, e.g. on a piece of paper. Better yet, write a few numbers on a piece of paper. Consider what the formula for each of those outputs would look like, given those numbers. Write those formulas on the piece of paper.

Now, consider what would happen to each of those formulas if you added another number to the list. Be sure to consider all types of number, e.g. don't forget about the case where the new number is larger than all the previous numbers.

Now, see if you can translate what you've done into code.

Edit: pronoun clarification
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
What are you doing with the data that was entered if it is not Zero?
 

darkmandaddy

Member
Dec 25, 2008
155
0
0
I forgot if its ++count or count++, but that keep track of how many integers. Slowly do one at a time.
Test

int sum, int,
int x = 1,
int average;
int count;

Do
{

cin>>int;
count++
sum = int + sum
}
While (x < 0) - //you might want to look up not equal too, because negative numbers aren't 0.
average = sum / count;

that's for average.
For largest and smallest, look in the book for that code.
Then large - small = diff.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
I think your problem is that you're not thinking properly. Now, that may sound like an odd thing to say, but I believe that most people get stuck on problems when they can't figure out what steps to take. You need to get out of thinking like a human and think in a basic manner like a PC would.

If you have issues generating what your steps need to be, you can literally "act out" the task at hand. Get out a piece of paper and draw a box labeled with the name of each variable. Now, I want you to just go through an example run of the program. While doing this, focus on what tasks you must do in between each time you ask the user for a new number... in this case, instead of asking for a new number, it's just you coming up with a new number.

To give some extra help...

Now, you do know what your tasks are... and you listed them very nicely here:
-the number of integers in the series ( not including 0)
- average of the integers
-largest integer in the series
-smallest in the series
- difference between the largest and smallest."

So in other words, you will need to do five things and each task (that could be one or more lines) will need to do one of the five things above.

I'll give you another piece of advice (this is something you'd probably notice while doing it manually). For the average, you will most likely not compute this each time. It is easier to simply add the numbers up and compute the average when you're done. This is also true for the difference between the largest and the smallest.

EDIT: I bolded while to show that in some cases, even speaking about the task at hand tends to give clues as to what kind of code you will use.
 

sao123

Lifer
May 27, 2002
12,650
203
106
all good advice above me so far...

one mroe thing...
tackle each of the 5 pieces as a seperate entity... do not try to program them all at once.

i'll give you a hint...

do them each in the order in which your question asks ... it will lead toward a progression which will make logical sence, each building on the last one.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |