Write your question here.
so, this is what i have. i wanted to include it all because i don't know what people need to see in order to tell if i have put things in the right place, but the only thing that i need help with is how to get an output that states the largest value and the smallest value of the external input.
int main()
{
int counter = 0; // counter for total number of input values
double user_input; // variable that holds the current input value
double average = 0.0; // variable that holds the average calculated
double sum_of_user_input = 0.0; // variable that holds the sum of the values inputted
double largest_value = 0.0; // variable that holds the largest value inputted
double smallest_value = 0.0; // variable that holds the smallest value inputted
bool more_entry = true; /* a flag to indicate whether the just input value is to be
* processed as one of the input values or if it is just a
* value to indicate NO MORE. it begins under the assumption
* that we have more input values to come */
cout << "Please enter a non-negative number! (Entering a number < 0 means you want to end input): \n";
cin >> user_input;
if (user_input < 0) // if the input is less than zero
{
more_entry = false; // then 'turn the flag' and avoid entering the loop
}
while (more_entry == true) // while this new input is a valid input value
{
counter = counter + 1; // incrementing the count of the non-negative numbers
sum_of_user_input = sum_of_user_input + user_input; // keeping a running total
cout << endl;
cout << "Please enter a non-negative number (< 0 means you are finished): \n";
cin >> user_input;
if (user_input < 0)
{
more_entry = false; // no more input values from user
}
}
cout << endl;
if (counter > 1)
{
average = sum_of_user_input / counter; // defining the average
cout << "Total number of valid input values accepted: " << counter << endl;
cout << "The average of all input values is: " << average << endl;
cout << "The sum of all input values is: "<< sum_of_user_input << endl;
if (largest_value <= user_input)
{
largest_value = user_input; // if the user input is >= current largest number, then it takes that value
cout << "The largest value inputted is: " << largest_value << endl;
}
if (smallest_value >= user_input)
{
smallest_value = user_input;
cout << "The smallest value inputted is: " << smallest_value << endl;
}
} // this ends if counter > 1
else // counter is <= 1
{
if (counter == 1)
{
cout << "Since you only inputed one non-negative number, the ";
cout << "average is the input value: " << sum_of_user_input << ".\n";
} // this ends if counter is equal to 1
else //counter is < 1
{
cout << "You have not inputted any value. ";
cout << "I cannot calculate the average." << endl;
} // this ends else counter < 1
} // this ends else counter <= 1
cout << "Bye!" << endl;
return 0;
system("PAUSE");
}
i have been working on this for hours today and cannot seem to figure it out...any help would be hugely appreciated!
this is the part that i am focused on. i am assuming it is in the right place and that my logic is just flawed...i can't seem to figure this out...
1 2 3 4 5 6 7 8 9 10
if (largest_value <= user_input)
{
largest_value = user_input; // if the user input is >= current largest number, then it takes that value
cout << "The largest value inputted is: " << largest_value << endl;
}
if (smallest_value >= user_input)
{
smallest_value = user_input;
cout << "The smallest value inputted is: " << smallest_value << endl;
}