[prog] C++
wolf
wolf at wolfrising.net
Fri Dec 12 20:26:33 EST 2003
Hi,
I'm trying to teach myself a bit of C++ following along with a book,
the sample asks to have three numbers entered in via the screen
that print back the sum, average, product, largest, and smallest of the
numbers. I think I have it working for the first three
(sum, average, and product) but I'm having trouble trying to figure out
how to make it select the largest and smallest of the
three numbers. Would anyone know how to do this? Here's what I've come
up with so far that seems to return the correct
responses. I'm at the very beginning part of being a beginner : )
Thanks : )
#include <iostream>
int main()
{
//sum
int integer1;
int integer2;
int integer3;
int sum;
std::cout << "Let's add three numbers together: Enter the first
integer\n";
std::cin >> integer1;
std::cout << "Enter the second integer\n";
std::cin >> integer2;
std::cout << "Enter the third integer\n";
std::cin >> integer3;
sum = integer1 + integer2 + integer3;
std::cout << "The sum is " << sum << std::endl;
// average
int average;
std::cout << "Let's find the average of three numbers: Enter
the first integer\n";
std::cin >> integer1;
std::cout << "Enter the second integer\n";
std::cin >> integer2;
std::cout << "Enter the third integer\n";
std::cin >> integer3;
average = (integer1 + integer2 +integer3) / 3;
std::cout << "The average is " << average << std::endl;
//product
int product;
std::cout << "Let's multipy three numbers together: Enter the
first integer\n";
std::cin >> integer1;
std::cout << "Enter the second integer\n";
std::cin >> integer2;
std::cout << "Enter the third integer\n";
std::cin >> integer3;
product = integer1 * integer2 * integer3;
std::cout << "The product is " << product << std::endl;
//smaller
//larger
return 0;
}
More information about the Programming
mailing list