/*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;
}
csha_cs508
0
Newbie Poster
Recommended Answers
Jump to PostA 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 …
Jump to PostIf 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 …
All 6 Replies
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
csha_cs508
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
csha_cs508
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
csha_cs508
0
Newbie Poster
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.