1
Hello, I’m studying from Bjarne’s book "PROGRAMMING Principles and Pratice Using C++". I’m trying to make Drill number one chapter four. The exercise tells you to make a program that consists of a while-loop that reads and prints two integers and stops when it is written |, however, when I write | (or anything other than a number) the program is in an infinite loop. If anyone can explain to me what is wrong with my code, I have tried to read in the book about conversions from int to char and vice versa and yet the error persists, take a look.
#include <...\Projects\std_lib_facilities.h>
int main()
{
//drill's
//1 - inicio
/*escrever um programa que consiste em um while-loop que leia dois int e termine quando
é escrito | */
int n=0, n1=0;
cout << "Write a int. To stop the program hit |";
while (n != '|' || n1 != '|' )
{
cin >> n >> n1;
system("cls");
cout << n << " " << n1 << "\n";
}
}
Is there anything that says that the variables need to be
int
? Can you put the exercise statement? Or is that all there is to it?– Maniero
/*write a program consisting of a while-loop that reads two int and ends when is written | */ is this, I will comment below the original of the book.
– Leonardo V. De Gasperin
Write a program that consists of a while-loop that (each time Around the loop) reads in two int and then prints them. Exit the program when a terminating '|' is entered.
– Leonardo V. De Gasperin
I’m trying to understand the intention of doing this to give an answer.
– Maniero
OK thanks so much while doing a review on Cap if I find something posted here @bigown
– Leonardo V. De Gasperin
This was asked in the OS, but it seems that the exercise is another :)
– Maniero
It’s the Gomiero passed the link
– Leonardo V. De Gasperin