/*a program that inputs three integers from the 
keyboard and prints the sum, average, product, 
smallest and largest of these numbers*/

#include <iostream>
using namespace std;

int main()

{
    int firstNum, secondNum, thirdNum, sum, product,average, largest, smallest;
    
    cout<<"Enter three integers: ";
    cin>>firstNum;
    cin>>secondNum;
    cin>>thirdNum; 
     
    sum = firstNum+secondNum+thirdNum;
    product = firstNum*secondNum*thirdNum;
    average = product/3;
    
    
    cout<<"Sum is "<<sum <<"\n";
    cout<<"Product is "<<product <<"\n";
    cout<<"Average is "<<average <<"\n";  
    
//code for finding the largest number

    if(firstNum>secondNum)
    {
     if(firstNum>thirdNum)
    {
     cout<<"Largest is "<<firstNum<<"\n";
    }
    else if(thirdNum>firstNum)
    {
     cout<<"Largest is "<<thirdNum<<"\n";
     }
     else if(thirdNum==firstNum)
     {
     cout<<"Largest are "<<firstNum<<" and "<<thirdNum<<"\n";
     }
     }
     else if(secondNum>thirdNum)
     {
     if(secondNum>firstNum)
     {
     cout<<"Largest is "<<secondNum<<"\n";
     }
     if(secondNum==firstNum)
     {
     cout<<"Largest are "<<firstNum<<" and "<<secondNum<<"\n";
     }
     }
     else if(thirdNum>firstNum)
     {
     if(secondNum==thirdNum)
     {
     cout<<"Largest are "<<secondNum<<" and "<<thirdNum<<"\n";
     }
     else
     {
     cout<<"Largest is "<<thirdNum<<"\n";
     }
     }
     else if(firstNum==secondNum && secondNum==thirdNum)
     {
     {
     cout<<"All are equal.\n";
     }
     }
//end of the code for largest number
//**************************
//code for finding the smallest number
    if(firstNum<secondNum)
    {
     if(firstNum<thirdNum)
    {
     cout<<"Smallest is "<<firstNum<<"\n";
    }
    else if(thirdNum<firstNum)
    {
     cout<<"Smallest is "<<thirdNum<<"\n";
     }
     else if(thirdNum==firstNum)
     {
     cout<<"Smallest are "<<firstNum<<" and "<<thirdNum<<"\n";
     }
     }
     else if(secondNum<thirdNum)
     {
     if(secondNum<firstNum)
     {
     cout<<"Smallest is "<<secondNum<<"\n";
     }
     if(secondNum==firstNum)
     {
     cout<<"Smallest are "<<firstNum<<" and "<<secondNum<<"\n";
     }
     }
     else if(thirdNum<firstNum)
     {
     if(secondNum==thirdNum)
     {
     cout<<"Smallest are "<<secondNum<<" and "<<thirdNum<<"\n";
     }
     else
     {
     cout<<"Smallest is "<<thirdNum<<"\n";
     }
     }
     else if(firstNum==secondNum && secondNum==thirdNum)
     {
     {
     cout<<"All are equal.\n";
     }
     }
//end of the code for finding the smallest number              
    
    cout<<"\n\nPress any key and ENTER to EXIT";
    
    char response;
    cin>> response;
    
    return 0;
}

Dani AI

Generated

A few focused corrections and a simpler flow you can drop into the diagram. As pointed out, the average must be based on the sum (not the product) and you need a non-integer division to keep fractional results; make the average a double and divide by 3.0 (or cast the integer sum to double). For : also watch types — the product of three ints can overflow int for large inputs, so consider long long for product (or validate input range).

Keep the flowchart small and single-pass: input the three values, compute sum and product immediately, initialize largest and smallest to the first value, then compare the second and third in sequence, updating both min and max as needed, compute average, output, end. That avoids duplicating separate "largest" and "smallest" branches and makes the diagram tidy.

Example pseudocode (for the flowchart body):

read a, b, c
sum = a + b + c
product = (long long)a * b * c
largest = smallest = a
for each x in [b, c]:
    if x > largest then largest = x
    if x < smallest then smallest = x
average = sum / 3.0
print sum, product, average, smallest, largest

Notes and pitfalls: initialize product to 1 (not 0); decide whether ties need special text (most assignments accept a single largest/smallest); use std::min/std::max or a small loop for cleaner code; format the average with std::fixed/std::setprecision when you want a specific number of decimals. This keeps both the code and the flowchart compact and robust.

Recommended Answers

All 6 Replies

A couple of things to check:
What is the definition of average? You do not have the formula correct.
Secondly, if you have the numbers 1,3,4 (for example) will your average be an integer?

What you are neglecting in your if/else cluster there is that you can test for more than one condition at a time, e.g. if(firstNum > secondNum && firstNum > thirdNum) will cut down on the number of steps. Your specification only asks for the largest and smallest, so if there are two smallest it doesn't matter which is which (at least in my opinion, your instructor may feel differently).

For the flow charting, just go through the steps of your if/else and write them out on paper noting the different paths, make branches off of the earlier tests. For the other portion with the sum, product, and average the calculations can probably be listed as a single step (plus an additional step for the average from the earlier result).

thanks for posting... yeah, the output in the average is also an integer, thats why i did not declare the average to be double or float... anyway the average is just the sum of three numbers divided by 3... should i make the average as average = (firstNum*secondNum*thirdNum)/3;?

If you leave the average as an integer you will lose the decimals. That's what I was saying, if you have 1 + 3 + 4 = 8/3 = 2.6666etc will become 2

You have the average incorrectly in your code as the product/3. It needs to be the sum.

I'm checking for the sake of your sanity, I'm assuming this if/else bit is specified in your assignment. If it isn't you could get the whole thing done in just a few lines (fewer with a for loop).

ah... yah, got your point.. sorry, i didnt notice... my prob is, how will i connect the flowchart of the smallest and largest no... i have a different flowchart of the two?... let me declare the average as double.. tnx

Combine them into one procedure:

Are any of them equal to each other
    Yes: Move to next step
    No:  Is the first the largest?
         Yes: Set largest to first
              Is the second greater than the third?
              Yes: Set smallest to third

Etc.

okhei... thank you... such a great help...

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.