I have the majority of this program written but I see flaw in it the last section after the do while statement i think needs to be another array probably close to the one on top but I just cant seem to get it. If anyone could help that would be great. The program asks the user several times for you to enter a positive integer up until you enter -1 to exit the loop. Then lets say you do four inputs and on the fifth prompt you enter -1. This would mean an output would show 4 integers entered, once you enter -1 the program then asks you to enter a string as many times equal to how many integers you just entered, example:
"please enter a positive integer (-1 to exit): 1
"please enter a positive integer (-1 to exit): 2
"please enter a positive integer (-1 to exit): 3
"please enter a positive integer (-1 to exit): 4
"please enter a positive integer (-1 to exit): -1
"please enter string: hello
"please enter string: to
"please enter string: you
"please enter string: guys
The output for this should be:
1 : : hello
2 : : to
3 : : you
4 : : guys
but instead when the code is compiled and the input stored the output is this:
1 : : guys
2 : : guys
3 : : guys
4 : : guys
The string part of this code I want to become an array so as to make work the right way but I am not sure how. Here is my code with comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word;
int integer[100];
int integerVar=-1;
do
{
integerVar = integerVar + 1;
if (integerVar > 100)
{
cout << "Highest possible amount is 100";
break;
}
cout << "Enter a positive integer (-1 to exit): ";
cin >> integer[integerVar];
}
while (integer[integerVar] != -1);
cin.ignore(); // I want an array for 'word' to make the expected output just need a lil help
string word[100];
int wordVar = wordVar + 1;
while (word[wordVar] < integer[integerVar])
{
cout << "Enter a string: ";
cin >> word[wordVar];
}
}
| |