have no idea how to debug this?

// THE ERROR(S) THAT I NOTICE IS THAT IT WILL NOT PRINT OUT THE SUPPOSE VALUES.

// I BELIEVE THAT I HAVE ALL MY EQUATIONS CORRECT.







// This program asks for a series of numbers, from 1 to 10. If a user

// incorrectly enters a number outside the range, the program tells the

// user that a mistake was made and asks if another number should be

// entered. It repeats this step until a user no longer wishes to enter any

// more numbers.

//

// When this happeneds, the program prints the following information to the

// screen: the largest number entered, the smallest number entered, the sum,

// the average, and the amount of valid number entries.





#include

int main ()

{

char key_press;

int average = 0, largest_number = 0, number = 0, smallest_number = 0, sum = 0, valid_entries = 0;



do

{

cout << "Enter in a number, from 1 to 10. " << endl;<br>
cout << "Your number=";<br>
cin >> number;





if (number >= 1 && number <= 10)<br>
{

for (int temp = 1; temp <= valid_entries; temp++)<br>
{

if (valid_entries==0)

{

smallest_number = number;

largest_number = number;

}

else

{

if (smallest_number > number)

{

smallest_number = number;

}

if (largest_number < number)

{

largest_number = number;

}

}



sum = sum + number;

average = sum / valid_entries;



}

}



else

{

cout << "Problem!" << endl;<br>
cout << "The number you entered," << number << ", is not in the range." << endl;<br>
}



cout << "Would you like to enter another number? " << endl;<br>
cout << "For Yes, press Y or y followed by the ENTER key.
"<br>
<< "For No, press any other key followed by the ENTER key." << endl;<br>
cout << "Your choice is: ";<br>
cin >> key_press;

}while (key_press == 'y' && key_press == 'Y');





cout << "You have entered " << valid_entries << " valid numbers." << endl;<br>
cout << "The sum of the valid numbers is " << sum << endl;<br>
cout << "The average of the valid numbers is " << average << endl;<br>
cout << "The largest number used in the calculation
"<br>
<< "of the sum and the average was " << largest_number << endl;<br>
cout << "The smallest number used in the calculation
"<br>
<< "of the sum and the average was " << smallest_number << endl;<br>


return 0;

}




Comments

  • instead of looking for letter values, look for number values. All characters have a number assigned to them. You can find the numbers that apply to each character by searching for 'ASCII' in the c++ help file. thia will send you to either the 0-127 or 128-255 listings depending on what you pick. I printed them out for quick reference.

    Also you used the and symbol ('&&') it should be or inclusive ('||')

    So instead of

    while (key_press == 'y' && key_press == 'Y');



    try

    while ( (key_press == 121) || (key_press == 89) );



    I hope that works for you!



    ~It's a lot of ass to kick,

    but somebody has to do it.

    ~TAlphaBravo


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories