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)
[code]//These program will print you the sum ,product ,average ,smallest and largest //when given any three integers
#include<iostream>
usingnamespace std;
int main()
int integer1; // declaration of the variables
int integer2;
int integer3;
int sum;
int average;
int smallest;
int largest;
{
std::cout<<"input your first integer\n";
cin>>integer1;
std::cout<<"input your second integer\n";
cin>>"integer2;
std::cout<<"input your third integer\n";
cin>>"integer3;
std::cout<<"you sum is"<<integer1+integer2+integer3;
std::cout<<"your average is"<<(sum)/3;
std::cout<<"you product is"<<integer1*integer2*integee3;
std::cout<<"your smallest integer is"<<smallest;
cin>>integer1<integer2<interger3;
std::cout<<"your largest integer is"<<largest;
cin>>integer1>integer2>integer3:
return 0;
}
[/code]
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 !!!
1) Your cin extraction is going the wrong way occasionally. It is >> always.
2) You are printing out largest/smallest before figuring out which one is the largest and smallest
3) You can't cin into an expression like you are, those lines are garbage anyway
i think i have fix this problem , but i want to know as to whether my way of finding smallest and largest value without the use of control structure is correct or else ?
i don't know how can i write this since i was told not to use control structures
.so is it possible that i can find a smallest and a largest value without the use of the control structures ? if so how ?
largest = integer1>integer2 ? integer1 : integer2;
//This is a conditional assignment
//we start with the variable to get the value (largest = ),
//then we have the condition (integer>integer2),
//followed by the '?' operator. this signals the end of the condition.
//then we have the possible values that can be assigned to the variable (integer1 : integer2)
//separated by a ':'
//if the condition is true, it returns the first possible value
//if it is false, it returns the second.