According to the limitation you specified, we cannot make new variables. Then we use what we have.
We repurpose repeat
to store the resulting string that will be the printed answer.
The "repeat" question now has an integer output so we don't waste a string variable on it. It sounds as "repeat?(1 - yes / 0 - no)"
.
We repurpose input2
to be a stop flag. If the "repeat?" question is answered as 0
or a string, the cycle stops.
#include <iostream>
using namespace std;
int x, input1, input2;
string repeat;
int main() {
input2 = 1;
while (input2 != 0) {
cout << "input1 : ";
cin >> input1;
repeat += std::to_string(input1) + " ";
cout << "repeat?(1 - yes / 0 - no) ";
cin >> input2;
}
cout << repeat;
}
After that, the console log can look roughly like this:
input1 : 2
repeat?(1 - yes / 0 - no) 1
input1 : 45
repeat?(1 - yes / 0 - no) 1
input1 : 2374521
repeat?(1 - yes / 0 - no) 0
2 45 2374521
If you get an error about std
not having to_string()
, add #include<string>
to the program. (link to the issue)