I got a small task to do and i wrote some code -as far as i learned till now - it should work but it shows an error when i start the program.I use the Visual Studio Team System 2008.
Here is the task :
Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. The screen dialog 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
#include <iostream>
using std::cin;
using std::cout;
int main()
{
int a ,b ,c;
int Sum ,Average ,Product ,Smallest ;
int Largest ;
cout << "Input three different integers: ";
cin >> a >> b >> c;
Sum = a + b + c;
Average = Sum / 3;
Product = a * b * c;
if (a < b)
if(a < c)
Smallest = a;
elseif(b < c)
Smallest = b;
else
Smallest = c;
if (a > b)
if (a > c)
Largest = a;
elseif (b > c)
Largest = b;
else
Largest = c;
cout << "Sum is " << Sum << "\n";
cout << "Average is " << Average << "\n";
cout << "Product is " << Product << "\n";
cout << "Smallest is " << Smallest << "\n";
cout << "Largest is " << Largest ;
return 0;
}
The error it shows is :
Run-Time Check Failure #3 - The variable 'Largest' is being used without
being initialized.
(Press Retry to debug the application)
The result from the original code(the one posted in the begining) is :
Input three different integers: 13 27 14
Sum is 54
Average is 18
Product is 4914
Smallest is 13
Largest is -858993460Press any key . . .(this is in run without debug mode)
Just before it shows the "Largest ... " it says there was a mistake :
Run-Time Check Failure #3 - The variable 'Largest' is being used without
being initialized.
(Press Retry to debug the application)