/*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;
}

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.