I'm given a homework that says:
write a program that when input any three integers from the keyboard and print
the sum , average , product , smallest and largest of these numbers.(and they say we must not use control structures when writing this program)
//These program will print you the sum ,product ,
//average ,smallest and largest //when given any three integers
#include<iostream>
usingnamespace std;
int integer1; // declaration of the variables
int integer2;
int integer3;
int sum;
int average;
int smallest;
int largest;
int main()
{
cout<<"input your first integer\n";
cin>>integer1;
cout<<"input your second integer\n";
cin<<"integer2;
cout<<"input your third integer\n";
cin<<"integer3;
cout<<"you sum is"<<integer1+integer2+integer3;
cout<<"your average is"<<(sum)/3;
cout<<"you product is"<<integer1*integer2*integer3;
cout<<"your smallest integer is"<<smallest;
cin>>integer1<integer2<interger3;
cout<<"your largest integer is"<<largest;
cin>>integer1>integer2>integer3:
return 0;
}
so when i try to compile , i get message saying i have a bug
so i do not understand how can i write this .
PLEASE HELP ME !!!
i have tried to fix my error
so
did i use a correct way of finding largest value and smallest value?
no. because cin reads from the standard input, it cant sort.
you have to sort it by yourself, but since you are not allowed to use controll structures you have to use the STL to find the largest/smallest number.
im a bit confused why you are not allowed, to use if-statements, but the STL provides a max-function. http://cplusplus.com/reference/algorithm/max/
and a function for the min of two inputs
i have once used if-statement but the lecturer said is he don't want it. infect i don't have to use any control structure . so is it possible to find largest and smallest any way?