Output and display the largest number inputted

I have already develop a program that to receive the users' input of a positive integer numbers and to output the average for all the inputted numbers.

Now I am asked to modify the program so that it can display the largest numbers received from the users' input. However, I am quiet confused with it and don't know what to do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>

main() {
	
	int input;
	int numbers[12];
	int index = 0;
	int i;
	int sum;
	float average=0.0;
	
    do{
		
         printf("Please input a positive integer, 0 to leave.\n");
	     scanf("%d", &input);
	     average = (average*index + input)/(index+1);
	     index++;   
  	     printf("The average is: %2.2f\n", average);
    }
    while(input!=0);
    printf("Now quit!\n");
    
}
i don't know c , use if ,else if statement
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
using namespace std;

int main()
{
    int num=0,num1=0;
    cin>>num>>num1;
    if(num>num1) // conditional statement
    cout<<num<<" is greater"<<endl;
    else
    cout<<num1<<" is greter"<<endl;
    return 0;
}



http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Your program shows "average" after each input. Why?

What are those variables on lines 6, 8 and 9? They are not used anywhere.

Lets say that I type two numbers: 1 and 0. The loop quits after the 0 and the average is 0.5, (because 1/2 = 0.5). Is that right?



Lets pretend that you have handled some input values and know how large the largest was.

Now you get a new value.
How could you know whether the new value is larger than the largest so far?
How you would be sure that the largest value so far is up to date after this input?

How large should the "largest value so far" be before the first input?
Topic archived. No new replies allowed.