| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Memory & arrays - C++ Question - Program Flow
Hello,
I am trying to write a program to so a user can enter data and store in an array. In my program below, I am using a while statement to validate the data but it executes even when the data is valid. Can anyone tell me why? Also is there a debugging option where it will show the order that statements in your program are being executed based on certain input? Thanks I appreciate all help. int main() { int *tests; // Dynamically allocated test score array. //int total; // Accumulator to calculate average //int average; // To hold average test score int numTests; // To hold number of tests int cntr; // Counter // Get the number of tests from user. cout << "How many test scores do you have? "; cin >> numTests; //Dynamically allocate array to hold test scores. tests = new int[numTests]; //Get test scores from user. for(cntr = 0; cntr < numTests; cntr++) { cout << "Enter test score " << (cntr + 1 ) << ": "; cin >> tests[cntr]; } while(tests[cntr] < 0) { cout << "Enter a number greater than 0."; cin >> tests[cntr]; } return 0; } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Memory & arrays - C++ Question - Program Flow |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|