cant make it stop, problem with small c++ code
-
i have this problem, i am an amateur in programming c++ so i made this simple program: i have d0, d1, d2, and d3, i give them some values, then i have a, b, c, d, e, f, and g, and i want to calculate them with a math operation for each one, but that operation uses the d0, d1, d2, d3 values that you gave them before with the cin's, so, after you give the values to d0, d1, d2, and d3, the program closes itself because it finishes doing everything but i cant see the results for the a, b, c, d, e, f, and g operations. Can someone help me please. This is my code: #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; main() { int d0, d1, d2, d3; int a, b, c, d, e, f, g; //Meto los valores 0 y 1 de las variables d0, d1, d2, d3 cout<< "Inserte los valores de las siguientes variables:\n"<<endl; cout<< "Variables: d0, d1, d2, d3\n"; cout<< "TIENEN QUE SER 0 o 1\n"; cout<< "Inserte d0\n"; cin>> d0; cout<< "Inserte d1\n"; cin>> d1; cout<< "Inserte d2\n"; cin>> d2; cout<< "Inserte d3\n"; cin>> d3; cout<< "Ahora se muestran los valores de cada segmento\n"; //Calculo los valores de las variables a, b, c, d, e, f, g, utilizando los valores de d0, d1, d2, d3 a= ((d0&&d2)||(!d0&&!d2)||(d1)||(d3)); b= ((d0&&d1)||(!d0&&!d1)||(!d2)||(d3)); c= ((d0)||(!d1)||(d2)||(d3)); d= ((!d0&&!d2)||(!d0&&d1)||(!d0&&d3)||(d1&&!d2)||(d1&&d3)||(d0&&!d1&&d2)); e= ((!d0&&d1)||(!d0&&d2)); f= ((d0&&d2)||(d0&d1)||(d2&&d2)||(d3)); g= ((!d0&&d1)||(!d1&&d2)||(!d1&&d2)||(d3)); //Muestro los valores en pantalla cout<< a <<"\n"; cout<< b <<"\n"; cout<< c <<"\n"; cout<< d <<"\n"; cout<< e <<"\n"; cout<< f <<"\n"; cout<< g <<"\n"; }
-
i have this problem, i am an amateur in programming c++ so i made this simple program: i have d0, d1, d2, and d3, i give them some values, then i have a, b, c, d, e, f, and g, and i want to calculate them with a math operation for each one, but that operation uses the d0, d1, d2, d3 values that you gave them before with the cin's, so, after you give the values to d0, d1, d2, and d3, the program closes itself because it finishes doing everything but i cant see the results for the a, b, c, d, e, f, and g operations. Can someone help me please. This is my code: #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; main() { int d0, d1, d2, d3; int a, b, c, d, e, f, g; //Meto los valores 0 y 1 de las variables d0, d1, d2, d3 cout<< "Inserte los valores de las siguientes variables:\n"<<endl; cout<< "Variables: d0, d1, d2, d3\n"; cout<< "TIENEN QUE SER 0 o 1\n"; cout<< "Inserte d0\n"; cin>> d0; cout<< "Inserte d1\n"; cin>> d1; cout<< "Inserte d2\n"; cin>> d2; cout<< "Inserte d3\n"; cin>> d3; cout<< "Ahora se muestran los valores de cada segmento\n"; //Calculo los valores de las variables a, b, c, d, e, f, g, utilizando los valores de d0, d1, d2, d3 a= ((d0&&d2)||(!d0&&!d2)||(d1)||(d3)); b= ((d0&&d1)||(!d0&&!d1)||(!d2)||(d3)); c= ((d0)||(!d1)||(d2)||(d3)); d= ((!d0&&!d2)||(!d0&&d1)||(!d0&&d3)||(d1&&!d2)||(d1&&d3)||(d0&&!d1&&d2)); e= ((!d0&&d1)||(!d0&&d2)); f= ((d0&&d2)||(d0&d1)||(d2&&d2)||(d3)); g= ((!d0&&d1)||(!d1&&d2)||(!d1&&d2)||(d3)); //Muestro los valores en pantalla cout<< a <<"\n"; cout<< b <<"\n"; cout<< c <<"\n"; cout<< d <<"\n"; cout<< e <<"\n"; cout<< f <<"\n"; cout<< g <<"\n"; }
-
i have this problem, i am an amateur in programming c++ so i made this simple program: i have d0, d1, d2, and d3, i give them some values, then i have a, b, c, d, e, f, and g, and i want to calculate them with a math operation for each one, but that operation uses the d0, d1, d2, d3 values that you gave them before with the cin's, so, after you give the values to d0, d1, d2, and d3, the program closes itself because it finishes doing everything but i cant see the results for the a, b, c, d, e, f, and g operations. Can someone help me please. This is my code: #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; main() { int d0, d1, d2, d3; int a, b, c, d, e, f, g; //Meto los valores 0 y 1 de las variables d0, d1, d2, d3 cout<< "Inserte los valores de las siguientes variables:\n"<<endl; cout<< "Variables: d0, d1, d2, d3\n"; cout<< "TIENEN QUE SER 0 o 1\n"; cout<< "Inserte d0\n"; cin>> d0; cout<< "Inserte d1\n"; cin>> d1; cout<< "Inserte d2\n"; cin>> d2; cout<< "Inserte d3\n"; cin>> d3; cout<< "Ahora se muestran los valores de cada segmento\n"; //Calculo los valores de las variables a, b, c, d, e, f, g, utilizando los valores de d0, d1, d2, d3 a= ((d0&&d2)||(!d0&&!d2)||(d1)||(d3)); b= ((d0&&d1)||(!d0&&!d1)||(!d2)||(d3)); c= ((d0)||(!d1)||(d2)||(d3)); d= ((!d0&&!d2)||(!d0&&d1)||(!d0&&d3)||(d1&&!d2)||(d1&&d3)||(d0&&!d1&&d2)); e= ((!d0&&d1)||(!d0&&d2)); f= ((d0&&d2)||(d0&d1)||(d2&&d2)||(d3)); g= ((!d0&&d1)||(!d1&&d2)||(!d1&&d2)||(d3)); //Muestro los valores en pantalla cout<< a <<"\n"; cout<< b <<"\n"; cout<< c <<"\n"; cout<< d <<"\n"; cout<< e <<"\n"; cout<< f <<"\n"; cout<< g <<"\n"; }
I don't understand but only a few words of the Spanish and I was too lazy to check the math because I don't understand it either..(think I need to know the comment right before it) Anyhow if you add getch(); or system("pause"); right before your final bracket that will fix the problem for you. *notes: system("pause") should be platform dependent, but works in windows.. you have to press the enter key before the program does anything else getch = get character, all it does it waits for any key at all to be pressed and then continues.. should work on any platform but you may accidently hit a key and close the program its common practice to include return 0; or return 1; but as you can see, not necessary .
-
i have this problem, i am an amateur in programming c++ so i made this simple program: i have d0, d1, d2, and d3, i give them some values, then i have a, b, c, d, e, f, and g, and i want to calculate them with a math operation for each one, but that operation uses the d0, d1, d2, d3 values that you gave them before with the cin's, so, after you give the values to d0, d1, d2, and d3, the program closes itself because it finishes doing everything but i cant see the results for the a, b, c, d, e, f, and g operations. Can someone help me please. This is my code: #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; main() { int d0, d1, d2, d3; int a, b, c, d, e, f, g; //Meto los valores 0 y 1 de las variables d0, d1, d2, d3 cout<< "Inserte los valores de las siguientes variables:\n"<<endl; cout<< "Variables: d0, d1, d2, d3\n"; cout<< "TIENEN QUE SER 0 o 1\n"; cout<< "Inserte d0\n"; cin>> d0; cout<< "Inserte d1\n"; cin>> d1; cout<< "Inserte d2\n"; cin>> d2; cout<< "Inserte d3\n"; cin>> d3; cout<< "Ahora se muestran los valores de cada segmento\n"; //Calculo los valores de las variables a, b, c, d, e, f, g, utilizando los valores de d0, d1, d2, d3 a= ((d0&&d2)||(!d0&&!d2)||(d1)||(d3)); b= ((d0&&d1)||(!d0&&!d1)||(!d2)||(d3)); c= ((d0)||(!d1)||(d2)||(d3)); d= ((!d0&&!d2)||(!d0&&d1)||(!d0&&d3)||(d1&&!d2)||(d1&&d3)||(d0&&!d1&&d2)); e= ((!d0&&d1)||(!d0&&d2)); f= ((d0&&d2)||(d0&d1)||(d2&&d2)||(d3)); g= ((!d0&&d1)||(!d1&&d2)||(!d1&&d2)||(d3)); //Muestro los valores en pantalla cout<< a <<"\n"; cout<< b <<"\n"; cout<< c <<"\n"; cout<< d <<"\n"; cout<< e <<"\n"; cout<< f <<"\n"; cout<< g <<"\n"; }
-
I don't understand but only a few words of the Spanish and I was too lazy to check the math because I don't understand it either..(think I need to know the comment right before it) Anyhow if you add getch(); or system("pause"); right before your final bracket that will fix the problem for you. *notes: system("pause") should be platform dependent, but works in windows.. you have to press the enter key before the program does anything else getch = get character, all it does it waits for any key at all to be pressed and then continues.. should work on any platform but you may accidently hit a key and close the program its common practice to include return 0; or return 1; but as you can see, not necessary .
-
by the way, a suggestion: make the
main()
function return an int; i.e.,int main()
. and addreturn 0
to the end of the code. it's good practice.Yeah I suggested the return 0 part but i failed to notice he didn't make main() an int or I would of mentioned that part too