• 0

[C++] cout smallest and largest number


Question

Alright guys!

I've started my journey into C++ an I'm slowly enjoying it. Part of my Homework assignment is to have a program that inputs 3 integers from the keyboard and prints the sum,avg, and product(which I got down fyi) What I'm needing is the print for the smallest and largest number

Screen Dialog should appear as follows

  Quote
Input three different integers: 13 27 14

Sum is 54

Average is 18

Product is 4914

Smallest 13

Largest is 27

I'll upload a pic of my work to show you where I'm at.

post-255423-1220588252_thumb.jpg

Link to comment
https://www.neowin.net/forum/topic/665578-c-cout-smallest-and-largest-number/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

#include <iostream>

using namespace std;

int main ()
{
	int numb1, numb2, numb3;

	cout << "Please enter first interger: ";
	cin >> numb1;
	cout << "Please enter second interger: ";
	cin >> numb2;
	cout << "Please enter third interger: ";
	cin >> numb3;
	cout << "Sum is " << numb1+numb2+numb3 << endl;
	cout << "Average is " << (numb1+numb2+numb3)/3 << endl;
	cout << "Product is " << numb1*numb2*numb3 << endl;

	if((numb1>numb2)&&(numb1>numb3))
	{
		cout << "Biggest number is " << numb1 << endl;
	}

	if((numb2>numb1)&&(numb2>numb3))
	{
		cout << "Biggest number is " << numb2 << endl;
	}

	if((numb3>numb1)&&(numb3>numb2))
	{
		cout << "Biggest number is " << numb3 << endl;
	}

	if((numb1<numb2)&&(numb1<numb3))
	{
		cout << "Smallest number is " << numb1 << endl;
	}

	if((numb2<numb1)&&(numb2<numb3))
	{
		cout << "Smallest number is " << numb2 << endl;
	}

	if((numb3<numb1)&&(numb3<numb2))
	{
		cout << "Smallest number is " << numb3 << endl;
	}

	return 0;
}

There is a better way but I don't remember it at the moment.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.