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.

Recommended Answers

All 3 Replies

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.

commented: Excellent advice for a beginner. +6
#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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.