Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. cant make it stop, problem with small c++ code

cant make it stop, problem with small c++ code

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rambache
    wrote on last edited by
    #1

    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"; }

    J G 3 Replies Last reply
    0
    • R rambache

      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"; }

      J Offline
      J Offline
      josda1000
      wrote on last edited by
      #2

      just before the last bracket in the program, add system("PAUSE"). This will only work if you're using Windows or DOS.

      1 Reply Last reply
      0
      • R rambache

        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"; }

        G Offline
        G Offline
        gamefreak2291
        wrote on last edited by
        #3

        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 .

        J 1 Reply Last reply
        0
        • R rambache

          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"; }

          J Offline
          J Offline
          josda1000
          wrote on last edited by
          #4

          by the way, a suggestion: make the main() function return an int; i.e., int main(). and add return 0 to the end of the code. it's good practice.

          G 1 Reply Last reply
          0
          • G gamefreak2291

            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 .

            J Offline
            J Offline
            josda1000
            wrote on last edited by
            #5

            looks like you and i are on the same page. glad we're quick on the keyboard :)

            1 Reply Last reply
            0
            • J josda1000

              by the way, a suggestion: make the main() function return an int; i.e., int main(). and add return 0 to the end of the code. it's good practice.

              G Offline
              G Offline
              gamefreak2291
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups