HOW TO WRITE THIS PROGRAM?

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)

look what i done so far


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[code]//These program will print you the sum ,product ,average ,smallest and largest //when given any three integers

#include<iostream>
using namespace 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 !!!
Last edited on
There is a typo on the second to last line of code - you have ended with a colon ':' rather than a semicolon ';'.

If the error persists, could you be more specific about it, i.e. give us the exact error message.

Also, you should put your code in [code][/code] tags to make it easier to read.

Hope this helps.

EDIT: You should also check for spelling errors - I can see at least one. These can, of course, cause compiler errors.
Last edited on
You have several errors:

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 ?
 
cin>>integer1<integer2<interger3;


this never not work
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 ?
1
2
3
4
5
6
7
8
9
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. 
Last edited on
thanks let me try this...
i'm probably trolling(?)

secret wrote:
is it possible that i can find a smallest and a largest value without the use of the control structures ?

Yes

if so how ?

http://www.cplusplus.com/reference/algorithm/min/
http://www.cplusplus.com/reference/algorithm/max/

edit: ah crap, secret why the feck are you opening two separate threads on the same subject -in two different forums? http://www.cplusplus.com/forum/general/39500/
Last edited on
A lot of beginners apparently do that out of fear they posted in the wrong forum when they don't get a response in the first 30 seconds.
Topic archived. No new replies allowed.