Code:#include <iostream> /*for cin and cout*/ int main() /*function main*/ { int num = 0; float sum= 0; float avg= 0; int count = 0; int largest = 0; int smallest= 0; int product = 0; while (1) //never ending loop//start loop body { std::cout <<"Please enter an integer enter (-1 to stop)"; std::cin >> num; if (num == -1) { break; //get out of the loop } else; sum += num; // start else body count++; avg = (sum)/count; if (count == 1) { smallest = largest = num; } else; // start else body; if (num < smallest) { smallest = num; if (num > largest) largest = num; else; //end body; } else; //end body; } //end loop body; product = (smallest * largest); //product = num * num?? std::cout << "The number of the integers is " << count << std::endl; std::cout << "The sum of the integers is " << sum << std::endl; std::cout << "The average of the integers is " << avg << std::endl; std::cout << "The product of the integers is " << product << std::endl; std::cout << "The largest integers is " << largest << std::endl; std::cout << "The smallest integers is " << smallest << std::endl; return 0; }
this board has been a tremendous amount of help and I have a couple of ???
1) If i enter three intergers into the program say 5 4 2 -1
everything work except my product out put it ends up with 10 instead of say 40, does that statement have to be in the while loop
somewhere???
2) smallest = largest = num; I'm a little confused about this statement if i enter say 5 4 2 is it ending up assigning 2 to num after the program runs???
many thanks to all



LinkBack URL
About LinkBacks



still confused about what