Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Program problem --

Status
Not open for further replies.

dare

ISP
Mar 18, 2002
2
0
0
US
I need to make a Program that will ask the user to enter the number of values that will be entered and then read it in. After that, the user is prompted for a value and fiven the oppurtunity to enter a value n times (where n is the number of values to be entered by the user).

After all n values are entered, i need to make it print the average of the numbers as well as the large and small number.

I KNOW how to average the numbers but i dont know how to get the program to only allow you to enter a certain number of numbers and i dont know what to do to get it to print the large and smallest numbers! PLEASE HELP!
 
Simple,
*The number of times will be a global variable.
*To print use cout and cin ( look the help)


 
We aren't allowd to use global variables, and weren't taught how too!
 
You have a while or a for loop to read in 'n' numbers..something like this..

for (int i = 0; i < n; i++)
{
scanf (&quot;%d&quot;, &amp;myNum);
myArray = myNum;
}

To find the largest or the smallest.. u need a simple logic that can traverse the array and find the number... maybe like this...

int i = 1;
large = myArray[0];
while (i < n)
{
if (myArray > large)
large = myArray);
}

pritf (&quot;Largest = %d&quot;, large);

// the same is applicable to find the smallest number
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top