1
I’m making a code that receives three values and orders them from the highest to the lowest. As a condition, when the numbers are repeated, an error message is displayed and the program must close. If the numbers are distinct, it skips this if
and proceed to the actual ordination.
I used the following line of code:
if (z==x or y==z or x==y)
cout << "\nErro. Os valores devem ser diferentes. Tente novamente: \n" << endl;
//restante do código
However, even if the numbers are different, the program always displays the message
"Error. Values should be different. Try again:"
I would like it to be displayed only when there was the error, and in this case, the program should end right there, and not continue, because this is also occurring.
Below follows the complete code:
#include <iostream>
using namespace std;
int x,y,z,ft,sd,th;
int main()
{
cout << "Digite 3 valores reais e diferenteees: \n";
cin >> x;
cin >> y;
cin >> z;
if (z==y or x==z or x==y)
cout << "\nErro. Os valores devem ser diferentes de 0 e nao repetidos. Tente novamente: \n" << endl;
if (x>y and x>z)
ft=x;
else if (x>y and x<z)
sd=x;
else if (x>z and x<y)
sd=x;
else if (x<y and x<z)
th=x;
if (y>x and y>z)
ft=y;
else if (y<x and y>z)
sd=y;
else if (y<z and y>x)
sd=y;
else if (y<x and y<z)
th=y;
if (z>x and z>y)
ft=z;
else if (z<x and z>y)
sd=z;
else if (z<y and z>x)
sd=z;
else if (z<x and z<y)
th=z;
cout << "\nOs valores ordenados sao: \n" << endl;
cout << "Valor mais alto: " << ft<< endl;
cout << "Valor intermediario: " << sd<< endl;
cout << "Valor mais baixo: " << th<< endl;
return 0;
}
You’re confused, mainly because you’re not putting in your real code. But it actually seems that you ignored the answers given to you in the other question. If you insist on doing wrong it will not work. http://answall.com/questions/53261/problemas-com-or-em-c. You must [Edit] the question and place your code to be analysed, please read this http://answall.com/help/mcve
– Maniero
As you said 'getting the hang of Sopt', I will suggest that you read the [TOUR]. And the link @bigown posted is also quite interesting for you to find out how Sopt works.
– emanuelsn