Input and Output problem

How can I stop an input and start an output after the input of two 0's?If the input is for example:
1 3
2 4
0 0
I want to stop the input after that 0. I tried to solve this problems with a while loop but I get a runtime error.
For example, if I want to add two numbers the output should be:
4
6
Post your code you wrote to solve the assignment.

And PLEASE use code tags. They make it MUCH easier to read and comment on source code.

http://www.cplusplus.com/articles/jEywvCM9/
In principle this is one way how you can do it.

It might have to be varied depending how your input actually works, ie 2 numbers at a time or 6 ... or even if it is only one zero or two zeroes that stop further input. Only you know so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

int main()
{
    int number_1{0}, number_2{0};
    
    do{
        std::cout << "Enter 2 numbers: ";
        std::cin >> number_1 >> number_2;
        
        std::cout << number_1 << ' ' << number_2 << '\n';
    } while( number_1 != 0 or number_2 != 0 );
    std::cout << "THE END\n";
    
    
    return 0;
}



Enter 2 numbers: 1 3
1 3
Enter 2 numbers: 2 4
2 4
Enter 2 numbers: 0 0
0 0
THE END
Program ended with exit code: 0
1
2
3
4
5
#include <iostream>
int main() {
    for (int a, b; std::cin >> a >> b && (a || b); )
        std::cout << (a + b) << '\n';
}

Last edited on
Nothing retard to see there :)
:)
Thanks againtry and dutch for your help
Topic archived. No new replies allowed.