I'll write a program that asks the user for an (unknown) number of integers(positive and negative) and print mean and the sum of them. series should end with '0 '.
The program should also print the largest and second largest of the input, and will consist of a number of functions. (my doesn't, help pleease)
#include "stdafx.h"
#include <iostream>
#include <conio.h>
usingnamespace std;
int main ()
{
{
int inputnumbers, second_max=0, max=0, sum=0;
int n=0;
double mean;
cout << "enter some integers: ";
cin >> inputnumbers;
while(inputnumbers != 0)
{
sum += inputnumbers;
cin >> inputnumbers;
n++;
if(inputnumbers >= max )
{
second_max = max;
max = inputnumbers;
}
elseif(inputnumbers >= second_max)
{
second_max = inputnumbers;
}
}
mean = (double) sum / n;
cout << "Sum of the numbers you entered is: "<< sum << endl;
cout << "mean of the input is: " << mean << endl;
cout << "the largest number you entered is: " << max << endl;
cout << "the second largest number you entered is: " << second_max << endl;
}
_getch();
return 0;
}
expected output:
enter some integers: 44 15 6 -4 3 11 -7 9 0
Sum of the numbers you entered is: 77
mean of the input is: 9.625
the largest number you entered is: 44
the second largest number you entered is: 15
my output:
enter some integers: 44 15 6 -4 3 11 -7 9 0
Sum of the numbers you entered is: 77
mean of the input is: 9.625
the largest number you entered is: 15
the second largest number you entered is: 11
what am i doing wrong?? can somebody please help me fix it? :)
int main ()
{
{
int inputnumbers, second_max=0, max=0, sum=0;
int n=0;
double mean;
cout << "enter some integers: ";
while( cin>>inputnumbers, inputnumbers != 0 )
{
sum += inputnumbers;
cin >> inputnumbers;
n++;
if(inputnumbers >= max )
{
second_max = max;
max = inputnumbers;
}
elseif(inputnumbers >= second_max)
{
second_max = inputnumbers;
}
}
mean = (double) sum / n;
cout << "Sum of the numbers you entered is: "<< sum << endl;
cout << "mean of the input is: " << mean << endl;
cout << "the largest number you entered is: " << max << endl;
cout << "the second largest number you entered is: " << second_max << endl;
}
_getch();
return 0;
}
(WARNING: conversion from looser to doublelooser; possible loss of IQ)
#include "stdafx.h"
#include <iostream>
#include <conio.h>
usingnamespace std;
int main ()
{
{
int inputnumbers, second_max=0, max=0, sum=0;
int n=0;
double mean;
cout << "enter some integers: ";
while( cin>>inputnumbers, inputnumbers != 0 )
{
sum += inputnumbers;
n++;
if(inputnumbers >= max )
{
second_max = max;
max = inputnumbers;
}
elseif(inputnumbers >= second_max)
{
second_max = inputnumbers;
}
}
mean = (double) sum / n;
cout << "Sum of the numbers you entered is: "<< sum << endl;
cout << "mean of the input is: " << mean << endl;
cout << "the largest number you entered is: " << max << endl;
cout << "the second largest number you entered is: " << second_max << endl;
}
_getch();
return 0;
}