Okay, I am a third year student working on very basic C++ code. The instructions tell us that we need to use this template exactly as it is states below
#include <iostream> // allows program to perform input and output
int main()
{
int number1; // first integer read from user
int number2; // second integer read from user
int number3; // third integer read from user
int smallest; // smallest integer read from user
int largest; // largest integer read from user
int sum; // sum of integers read from user
double average; // average of integers read from user
int product; // product of integers read from user
std::cout << "Input three different integers: "; // prompt
/* Write a statement to read in values for number1, number2 and number3 using a single cin statement */
largest = number1; // assume first integer is largest
/* Write a statement to determine if number2 is greater than largest. If so assign number2 to largest */
/* Write a statement to determine if number3 is greater than largest. If so assign number3 to largest */
smallest = number1; // assume first integer is smallest
/* Write a statement to determine if number2 is less than smallest. If so assign number2 to smallest */
/* Write a statement to determine if number3 is less than smallest. If so assign number3 to smallest */
std::cout << "The answers are: "; /* Write an output statement that prints the largest, smallest, sum, average, and product */
} // end main
I have tried that with no results. However, I have been working with the code below which still need some work but has gotten me farther than anything else I have tried
#include <iostream> // allows program to outpput data to the screen
using std::cout;
// function main begins program execution
int main()
{
int number1; // first integer read from user
int number2; // second integer read from user
int number3; // third integer read from user
int smallest; // smallest integer read from user
int largest; // largest integer read from user
int sum; // sum of integers read from user
double average; // average of integers read from user
int product; // product of integers read from user
std::cout << "Input three different integers: ";
std::cin >> number1 >> number2 >> number3; // three integers from user
if ( number1 > number2 )
cout << "largest";
if (number2 > number1 )
cout << "largest";
if (number3 > number2 )
cout << "largest";
std::cout << "The answers are: " << largest << std::endl;
system("pause");return 0;
} // end function main
I still need to write in the code for smallest, sum, average, and product.
I keep getting these warning when I compile and run the code
warning C4101: 'average' : unreferenced local variable
warning C4101: 'product' : unreferenced local variable
warning C4101: 'sum' : unreferenced local variable
warning C4101: 'smallest' : unreferenced local variable
(28): warning C4700: uninitialized local variable 'largest' used
This is driving me insane. I have a book that's twice the thickness of the holy bible and can't find anything regarding the above mentioned errors in it. Any help would be appreciated.
#include <iostream> // allows program to outpput data to the screen
using std::cout;
// function main begins program execution
int main()
{
int number1; // first integer read from user
int number2; // second integer read from user
int number3; // third integer read from user
int smallest; // smallest integer read from user
int largest; // largest integer read from user
int sum; // sum of integers read from user
double average; // average of integers read from user
int product; // product of integers read from user
std::cout << "Input three different integers: ";
std::cin >> number1 >> number2 >> number3; // three integers from user
largest = number1;
if ( number1 > number2 )
cout << "largest";
std::cin >> number1;
if (number2 > number1 )
cout << "largest";
std::cin >> number2;
if (number3 > number2 )
cout << "largest";
std::cin >> number3;
std::cout << "The answers are: " << largest << std::endl;
system("pause");return 0;
} // end function main
I'm still trying to figure out how to come up with the largest number to no avail. What am I missing here?
It shows you how to find the largest number in a array.
You could read your numbers to an array then use code/logic from the link.
It is in C but C++ is C inclusive.
#include <iostream> // allows program to perform input and output
int main()
{
int number1; // first integer read from user
int number2; // second integer read from user
int number3; // third integer read from user
int smallest; // smallest integer read from user
int largest; // largest integer read from user
int sum; // sum of integers read from user
double average; // average of integers read from user
int product; // product of integers read from user
std::cout << "Input three different integers: "; // prompt
/* Write a statement to read in values for number1, number2 and number3 using a single cin statement */
largest = number1; // assume first integer is largest
/* Write a statement to determine if number2 is greater than largest. If so assign number2 to largest */
/* Write a statement to determine if number3 is greater than largest. If so assign number3 to largest */
smallest = number1; // assume first integer is smallest
/* Write a statement to determine if number2 is less than smallest. If so assign number2 to smallest */
/* Write a statement to determine if number3 is less than smallest. If so assign number3 to smallest */
std::cout << "The answers are: "; /* Write an output statement that prints the largest, smallest, sum, average, and product */
} // end main
and add in the cin statements and make it work. I have not been able to get it to work without adding additional statements aside from cin statements. According to your professional opinion, is this possible?
I never usually write code like this, but you could technically do the rest by only adding cin statements other than the part where you check for smallest and largest numbers.
#include <iostream> // allows program to perform input and output
int main()
{
int number1; // first integer read from user
int number2; // second integer read from user
int number3; // third integer read from user
int smallest; // smallest integer read from user
int largest; // largest integer read from user
int sum; // sum of integers read from user
double average; // average of integers read from user
int product; // product of integers read from user
std::cout << "Input three different integers: "; // prompt
/* Write a statement to read in values for number1, number2 and number3 using a single cin statement */
std::cin >> number1 >> number2 >> number3;
largest = number1; // assume first integer is largest
/* Write a statement to determine if number2 is greater than largest. If so assign number2 to largest */
if (number2>largest)
largest=number2;
/* Write a statement to determine if number3 is greater than largest. If so assign number3 to largest */
if (number3>largest)
largest=number3;
smallest = number1; // assume first integer is smallest
/* Write a statement to determine if number2 is less than smallest. If so assign number2 to smallest */
if (number2<smallest)
smallest=number2;
/* Write a statement to determine if number3 is less than smallest. If so assign number3 to smallest */
if (number3<smallest)
smallest=number3;
//Next calculate the sum
std::cout << "The answers are...\n"; /* Write an output statement that prints the largest, smallest, sum, average, and product */
std::cout << "Largest Value:" << largest << std::endl;
std::cout << "Smallest Value:" << smallest << std::endl;
std::cout << "Sum: " << (sum = (number1 + number2 + number3)) << std::endl;
std::cout << "Average: " << (average = (number1+number2+number3)/3.0f) << std::endl;
std::cout << "Product: " << (product = (number1*number2*number3)) << std::endl;
system("pause");
} // end main
Thanks Pindrougt, that is were I was running into issues. From my research online, I couldn't find anybody who rode code like this so it was hard to find a comparable example. I thank and my wife thanks you. I have been sitting in from of the computer for the last eight hours trying to work through the code, now I can take her to dinner.