Hi, I need to write a program that asks for a series of numbers, and when 0 is entered I need it to display the following:
the number of integers in the series
the average of the integers
the largest and smallest integer
the difference between the largest and smallest.

so far this is what I have:

#include <iostream.h>

main ()
{
int num[1];
int j = -1;

do 
{
    cout << "enter a number ";
cin >> num[1];
j++;
if (num[1] == 0)
{break;} 
}
while (1);
cout << num[1] << endl;
cout << j;
return 0;
}

I know that the code is pretty bad but I'm pretty new at this.
j calculates the ammount of times an integer was entered.
so I guess i have a little done. What I'm having trouble with is figuring out a way to keep track of which numbers were entered. If i could just figure that out it looks like the rest should just click.
thanx

Recommended Answers

All 2 Replies

>What I'm having trouble with is figuring out a way to keep track of which numbers were entered.
You're on the right track with this:

int num[1];

An array of one is pretty useless, but if you change that to, say 10, you can use j to figure out how many numbers there were and another index to print them:

for ( int i = 0; i < j; i++ )
  cout<< num[i] <<endl;

ok, so where would I add the for loop in? do i get rid of the do-while loop or add it in with it or what? I'm not sure if this really makes a difference but I need to make the program work for positive and negative numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.