asked 12.7k views
0 votes
Jump to level 1

Read string integer value pairs from input until "Done" is read. For each string read, if the following integer read is less than or equal to 45, output the string followed by ": reorder soon". End each output with a newline.

Ex: If the input is Tumbler 49 Mug 7 Cooker 5 Done, then the output is:

Mug: reorder soon
Cooker: reorder soon

how do i do this in c++

1 Answer

2 votes

Answer: #include <iostream>

#include <string>

using namespace std;

int main() {

string input;

int value;

while (true) {

cin >> input;

if (input == "Done") {

break;

}

cin >> value;

if (value <= 45) {

cout << input << ": reorder soon" << endl;

}

}

return 0;

}

Explanation: hope it helps :)

answered
User Zamblek
by
8.4k points

No related questions found