please help i would like to Write a program that inputs three integers from the keyboard
and prints the sum, average, product, smallest and largest of these numbers.

3 Years
Discussion Span
Last Post by Jamblaster

Do it in small parts so that you don't get overwhelmed. First, write the program and inputs three integers. After you get that working, you can add some more to sum up the three integers as you enter them. After that, so each of the other parts, and soon you will have the program written.

Votes + Comments
Excellent advice for a beginner.
#include <iostream>

int main()
    //prompt for integers
    //read/extract integers into variables
    //do calculations

What you really want to do is to use functions to perform your processing or classes (but function are really more appropriate here). The prototypes might look something like this:

void get_user_input(void);
void get_sum(int*, int*, int*);
void get_average(int*, int*, int*);
void get_product(int*, int*, int*);
void get_smallest_and_largest(int*, int*, int*);

You could declare some variables in main that might look like this:

int int_1 = int_2 = int_3 = 0;
int* ptr_1 = &int_1, ptr_2 = &int_2, ptr_3 = &int_3;

Then you could pass the pointers to each of the functions and use those functions and the pointers in the functions to sum (1 + 2 + 3), average((1 + 2 + 3) / 3), product (1 * 2 * 3), and get smallest and largest using if-else statements in that functions. Basically, the best way to break up any problem, big or small, (as noted above) is one step at a time--and in C++ the best way to do this is through classes or functions and so the best way to solve this problem (in my opinion anyway) is to go ahead and break it up into small pieces which are really simple to understand and write. You don't absolutely have to use pointers, but they are a great way to pass variable values back and forth while using relatively small amounts of memory (which is good). Anyway, that's just what I would do and when you get used to breaking a problem into functions it makes solving more complex problems a lot easier.

Edited by Jamblaster: quick fix

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.