- Write a program that consists of a while-loop that (each time around the loop) reads in two ints and then prints them. Exit the program when a terminating '|' is entered.
How do you write this?
When I check to see if either int is equal to |
they never do because their value is zero if |
is entered. My program currently repeats forever if |
is entered. I don't know how to access the correct value of the non int |
by using ints nor how to stop it from repeating forever.
1 - #include <iostream>
2 -
3 - using namespace std;
4 -
5 - int main()
6 - {
7 - int val1=0, val2=0;
8 - while(val1 != '|' && val2 != '|')
9 - {
10- cout << "Enter 2 integers, terminate with \"|\"" << endl;
11- cin >> val1;
12- if (val1 == '|')
13- {
14- return 0;
15- }
16- cin >> val2;
17- if (val2 == '|')
18- {
19- return 0;
20- }
21- cout << val1 << " " << val2 << "\n\n";
22- }
23-
24- return 0;
25- }