have problems creating a program that finds the Smallest largest and average of five numbers between 1 and 1000

if any one can help me i would be very greatful.

the only part i have is the <isostream.h>, and from there i have no clue what to do and i spent all night printing out strategies that would help but I do not understand any of it.
closed account (Lv0f92yv)
You'll probably want a loop.

Loop over all the values (the five numbers in this case), and maintain 2 variables - one for the smallest value seen so far and another for the largest value seen so far. Init them to impossible values (0, and 1001), since it looks like you're guaranteed to never see either of those in your real data set.

If the number your looking at is smaller than the smallest stored so far, update it. Same for largest. For average, just add them all up and divide by the number of numbers.

If you start coding and have problems, post what you have and we'll take another look.

Cheers.
Last edited on
I think i got the loop i am not sure:

While count<5
{if input < smallest
input=smallest
if input > largest
input=largest}

sum = input1+input2+input3+input4+input5
Average=sum/5

count<< smallest largest Average



i think that i got that part.
You should use <iostream> and not <iostream.h>
You should declare count, input, smallest = 1001, largest = 0, total = 0, sum, and Average.
You should ask the user to input count.
while is lower case, remember C++ is case-sensitive.
You should cin >> input; as the first thing in the loop.
You should put () around count < 5
You should put () around input < smallest
You should change input = smallest to smallest = input;
You should put () around input > largest
You should change input = largest to largest = input;
You should add the value of input to sum inside the while loop.
Average should be sum divided by count instead of 5.
count << smallest largest Average should be cout << smallest << endl << largest << endl << Average;

Other than that, it seems pretty good ;)
Last edited on
so the program should look like this:

<isostream>

int main()

{smallest=1000
largest=1
total=0

count<< "please choose five numbers between 1 and 1000";

while (count<5)
{cin>>input;
if input<smallest
smallest=input;
if input>largest
largest=input;
sum= value (input1+input2+input3+input4+input5)}

Average=sum/count
Count<<smallest<<enld<<largest<<enld<<Average;

return=0}
Last edited on
No it shouldn't. You have various mistakes like forgetting brackets, forgetting data types, using capital letters when they aren't needed, etc. Going over the tutorial at http://cplusplus.com/doc/tutorial will probably help review the syntax.
i printed out the tutorial and i couldn't understand a thing, and i am so lost.
You should than start with a more basic program, depending on what chapter you are reading right now. If you don't understand something in the tutorial, you should probably go back.
the thing is that to my teacher this is the most basic program and i have printed out all his examples and the tutorial yet i still do not know how to create the program stucture.

what i have so far is :

#<isostream>

void(cout,count,cin,average,value,sum,input) {smallest=1000,largest=1}

int main()

{ cout<< "please choose five numbers between 1 and 1000";

while (count<5)
{ cin>> input;
if input<smallest
smallest=input;
if input>largest
largest=input;
sum=value input}
average=sum/count

cout<<smallest<<enld<<largest<<enld<<average;
return=0;}

and i am not sure that i have everything correct.
based on the complier that i am using the main error i am getting is the void()
Please use the links @L B gave you. Your program just doesn't make sense* and I suggest you leave this program until you go over those parts of the tutorial.

* I does make some sense as a pseudo-code but you are writing C++ aren't you?
Last edited on
yes the program has to be in C++
I think i got the program i am not sure is the program suppose to look like this:

#include <iostream>
using namespace std;



int main ()
{ cout << "please choose five numbers between 1 and 1000";

int smallest, largest;
int a,b,c,d,e;
int result;
int average;
int count;
int input;
int enld;

smallest=1000;
largest=1;
result= a+b+c+d+e;
average= result/5;

while (count<5);
{ if(input<smallest)
smallest=input;
if (input>largest)
largest=input;}

result=a+b+c+d+e;

average=result/5;

cout<<smallest<<enld<<largest<<enld<<average;



return 0;
}
This is definitely an improvement but where do you get the numbers from the input?
You mixed largest and smallest and you calculated result and average twice (not that it means anything since you don't have the numbers.
the numbers would be :

cout<<"a= , b= , c=, d= , e= ,";



the only problem now is that my teacher wants it in void form not in int main form
Last edited on
closed account (Lv0f92yv)
I'm not sure what you/your teacher means by this... int main is simply the signature of your main program function. It is bad practice to be using void main (I do not see why your teacher would want that). Main is to return an integer value to runtime on completion. Some compilers support void main, most (good ones) do not.

If you want to read data into a variable (input from user), you could use:

cin >> a;

will wait for user input and store what they give you into a.

To output that value:

cout << a;

Perhaps your teacher wants you to write another procedure, which has a void return type, and is called in your main program. That would make more sense.
Topic archived. No new replies allowed.