mardi 27 janvier 2015

In my code everything works fine, when i debug i always get a 0 for smallest. why?


/* NOTE I JUST STARTED LEARNING C++. THIS IS SCHOOL WORK AND WOULD APPRECIATE IT IF SOMEONE TAUGHT ME INSTEAD OF GIVING THE ANSWER. THANKS */


int a = 0; int b = 0; int c = 0; int sum = 0; int average = 0; int product = 0; int largest = a; int smallest = a;



//Input
cout << "Enter the 3 Integers: ";
cin >> a >> b >> c;

//Output
cout << "Sum is ";
cout << (sum = a + b + c) << endl;

cout << "Average is ";
cout << (average = ((a + b + c) / 3)) << endl;

cout << "Product is ";
cout << (product = a * b * c) << endl;

if (b > largest)
largest = b;
if (c > largest)
largest = c;
if (b < smallest)
smallest = b;
if (c < smallest)
smallest = c;

cout << "largest is " << largest << endl;
cout << "Smallest is " << smallest << endl;


}





Aucun commentaire:

Enregistrer un commentaire