Ok this is kind of a bizzarre question but it's really bugging me.
The book I'm reading has barely covered the basics (only cout, cin, math, small if statements (not else if or anything like that), and that's about it. One of the excersizes at the end of the chapter is:
Now since I do know a little more about programming than the chapter I am currently in I did this:Quote:
Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. The screen dialogue should appear as follows:
Input three different integers: 13 27 14
Sum is 54
Average is 18
Product is 4914
Smallest is 13
Largest is 27
Thing is, he's never taught the && yet. So I'm thinking there is a way to do this without it. Is there? Please try to keep it basic. Yes, I know there are shorter ways to doing this, but I am just trying to follow my book right now. Thanks.Code://Outputs various facts.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int n1, n2, n3, sum, average, product;
cout<<"Input 3 integers: ";
cin>>n1>>n2>>n3;
sum = n1+n2+n3;
average = sum/3;
product = n1*n2*n3;
cout<<"Sum is "<<sum<<"\n";
cout<<"Average is "<<average<<"\n";
cout<<"Product is "<<product<<"\n";
if ( n1 < n2 && n1 < n3 )
cout<<"Smallest is "<<n1<<"\n";
if ( n2 < n1 && n2 < n3 )
cout<<"Smallest is "<<n2<<"\n";
if ( n3 < n1 && n3 < n2 )
cout<<"Smallest is "<<n3<<"\n";
if ( n1 > n2 && n1 > n3 )
cout<<"Largest is "<<n1<<"\n";
if ( n2 > n1 && n2 > n3 )
cout<<"Largest is "<<n2<<"\n";
if ( n3 > n1 && n3 > n2 )
cout<<"Largest is "<<n3<<"\n";
return 0;
}