I need help on how to write a program using C++

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
//These program will print you the sum ,product ,
//average ,smallest and largest //when given any three integers

#include<iostream>
using namespace 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?

Last edited on
you have to put you variables before main or in the main function, but not between main and its opening {.

what is that supposed to mean?
1
2
3
cin<<"integer2;
...
cin<<"integer3;

because you used the right syntax at cin>>integer1;

you dont initialize sum or largest or smallest

what is this?
1
2
3
cin>>integer1<integer2<interger3;
...
cin>>integer1>integer2>integer3;


fix your spelling errors (integee3, interger3)

why do you use the namespace std but write std::cout all the time?

i think you should read again what you have been taught in class.
i have fixed those errors , so have i used a correct way of finding the smallest and largest value ?
Last edited on
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.
Last edited on
what do you mean by STL and how it work ?
Standard Template Library

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
Last edited on
pass three integers into the max and min function, (call by value)
and end up returning a maximum/ minimum;

I thought the following functions you can came up with easily.

1
2
3
4
5
6
7
8
9
10
11
int max(arguement1, arguement2, arguement 3)
{
    ...
    return maximum;
}

int min(arguement1, arguement2, arguement 3)
{
    ...
    return minimum;
}

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?




1
2
3
4
5
6
7
8
9
10
int max(arguement1, arguement2, arguement 3)
{
    ...
    return maximum;
}

int min(arguement1, arguement2, arguement 3)
{
    ...
    return minimum;
[/code]



i hope this one will help ...thanks willyhsu let me give it a try
Topic archived. No new replies allowed.