| smquarterman (5) | |
|
I am having problems with my code involving arrays. I am asking the user to input letters until they enter an exclamation point. At that time, I am asking them to enter a number they want the letters to start reading, and a number they want to stop reading at. So if you enter h e l l o w o r l d, and entered a 3 and 7, my program would read llowo. All is good up til the point that the numbers are involved. Can anyone please help me? Thanks #include <iostream> using namespace std; int main () { char letter[100]; int n = 0; int NumIn; int NumOut; do { cout << "Enter letter (! to end): "; cin >> letter[n]; cout << "You entered: " << letter[n] << endl; n = n+1; } while (letter[n-1] != '!'); cout << "Please enter a number that you want to start reading in: " << endl; cin >> NumIn; cout << "Please enter a number that you want to stop reading :" << endl; cin >> NumOut; for (NumIn=0; NumIn<NumOut; NumIn++) { do { cout << letter << endl; }while (NumIn < NumOut); } return 0; } | |
|
|
|
| firix (438) | |
|
int main () { char letter[100]; int n = 0; int NumIn; int NumOut; do { cout << "Enter letter (! to end): "; cin >> letter[n]; cout << "You entered: " << letter[n] << endl; n = n+1; } while (letter[n-1] != '!'); letter[n] = '\0'; cout << "Please enter a number that you want to start reading in: " << endl; cin >> NumIn; cout << "Please enter a number that you want to stop reading :" << endl; cin >> NumOut; for (NumIn=0; NumIn<NumOut; NumIn++) { do { cout << letter << endl; }while (NumIn < NumOut--); } return 0; } | |
|
|
|
| vvadan (36) | |
|
in the code, you are not checking the character array limits. The user might input more than 100 characters | |
|
|
|