How to make a C program loop back to starting function?












0















For example, to this program that calculates equations of grade 3, after it calculates the equation, it stops. how do I make it so it loops back again to the start without executing again? I'm still new to this platform so I'll be in your care!



#include < stdio.h >

int main() {
int a, v, b, c, delt;
float x1, x2;

printf("nIntroduceti cele 3 parametrii ecuatia: ");

scanf("%d %d %d", & a, & b, & c);
if (a != 0) {
v = pow(b, 2);
delt = v - (4 * a * c);

if (delt >= 0) {

delt = sqrt(delt);
x1 = -(b + delt) / (2.0 * a);
x2 = -(b - delt) / (2.0 * a);

printf("nValoara lui x1 este: %f", x1);
printf("n");
printf("nValoara lui x2 este: %f", x2);

} else {
printf("Ecuatia nu are soluti! n");
}

} else if (a == 0) {
printf("nBLACKHOLE");
}

return 0;
}









share|improve this question





























    0















    For example, to this program that calculates equations of grade 3, after it calculates the equation, it stops. how do I make it so it loops back again to the start without executing again? I'm still new to this platform so I'll be in your care!



    #include < stdio.h >

    int main() {
    int a, v, b, c, delt;
    float x1, x2;

    printf("nIntroduceti cele 3 parametrii ecuatia: ");

    scanf("%d %d %d", & a, & b, & c);
    if (a != 0) {
    v = pow(b, 2);
    delt = v - (4 * a * c);

    if (delt >= 0) {

    delt = sqrt(delt);
    x1 = -(b + delt) / (2.0 * a);
    x2 = -(b - delt) / (2.0 * a);

    printf("nValoara lui x1 este: %f", x1);
    printf("n");
    printf("nValoara lui x2 este: %f", x2);

    } else {
    printf("Ecuatia nu are soluti! n");
    }

    } else if (a == 0) {
    printf("nBLACKHOLE");
    }

    return 0;
    }









    share|improve this question



























      0












      0








      0


      0






      For example, to this program that calculates equations of grade 3, after it calculates the equation, it stops. how do I make it so it loops back again to the start without executing again? I'm still new to this platform so I'll be in your care!



      #include < stdio.h >

      int main() {
      int a, v, b, c, delt;
      float x1, x2;

      printf("nIntroduceti cele 3 parametrii ecuatia: ");

      scanf("%d %d %d", & a, & b, & c);
      if (a != 0) {
      v = pow(b, 2);
      delt = v - (4 * a * c);

      if (delt >= 0) {

      delt = sqrt(delt);
      x1 = -(b + delt) / (2.0 * a);
      x2 = -(b - delt) / (2.0 * a);

      printf("nValoara lui x1 este: %f", x1);
      printf("n");
      printf("nValoara lui x2 este: %f", x2);

      } else {
      printf("Ecuatia nu are soluti! n");
      }

      } else if (a == 0) {
      printf("nBLACKHOLE");
      }

      return 0;
      }









      share|improve this question
















      For example, to this program that calculates equations of grade 3, after it calculates the equation, it stops. how do I make it so it loops back again to the start without executing again? I'm still new to this platform so I'll be in your care!



      #include < stdio.h >

      int main() {
      int a, v, b, c, delt;
      float x1, x2;

      printf("nIntroduceti cele 3 parametrii ecuatia: ");

      scanf("%d %d %d", & a, & b, & c);
      if (a != 0) {
      v = pow(b, 2);
      delt = v - (4 * a * c);

      if (delt >= 0) {

      delt = sqrt(delt);
      x1 = -(b + delt) / (2.0 * a);
      x2 = -(b - delt) / (2.0 * a);

      printf("nValoara lui x1 este: %f", x1);
      printf("n");
      printf("nValoara lui x2 este: %f", x2);

      } else {
      printf("Ecuatia nu are soluti! n");
      }

      } else if (a == 0) {
      printf("nBLACKHOLE");
      }

      return 0;
      }






      c






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 15:26









      terales

      1,7121526




      1,7121526










      asked Nov 22 '18 at 14:34









      Rami RaghfanRami Raghfan

      55




      55
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Just wrap your code into an infinite loop (while(1) { /* Your code here*/ }):



          #include < stdio.h >

          int main() {
          int a, v, b, c, delt;
          float x1, x2;

          while (1) {
          printf("nIntroduceti cele 3 parametrii ecuatia: ");

          scanf("%d %d %d", & a, & b, & c);
          if (a != 0) {
          v = pow(b, 2);
          delt = v - (4 * a * c);

          if (delt >= 0) {

          delt = sqrt(delt);
          x1 = -(b + delt) / (2.0 * a);
          x2 = -(b - delt) / (2.0 * a);

          printf("nValoara lui x1 este: %f", x1);
          printf("n");
          printf("nValoara lui x2 este: %f", x2);

          } else {
          printf("Ecuatia nu are soluti! n");
          }

          } else if (a == 0) {
          printf("nBLACKHOLE");
          }
          }

          return 0;
          }





          share|improve this answer


























          • I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

            – Rami Raghfan
            Nov 22 '18 at 14:46











          • It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

            – terales
            Nov 22 '18 at 14:50



















          1














          You could wrap everything in a do-while loop and ask the user whether he wants to continue the execution or not, for example:



          int a,v,b,c,delt;
          float x1,x2;
          char choice;
          do{
          printf("nIntroduceti cele 3 parametrii ecuatia: ");
          scanf("%d %d %d", &a, &b, &c);
          if(a!=0)
          {
          v=pow(b, 2);
          delt = v-(4*a*c);

          if (delt>=0)
          {
          delt=sqrt(delt);
          x1=-(b+delt)/(2.0*a);
          x2=-(b-delt)/(2.0*a);

          printf("nValoara lui x1 este: %f", x1);
          printf("n");
          printf("nValoara lui x2 este: %f", x2);
          }
          else
          {
          printf("Ecuatia nu are soluti! n");
          }
          }
          else if(a==0)
          {
          printf("nBLACKHOLE");
          }
          printf("nEvaluate new equation?(y/n) ")
          scanf("%c",&choice)
          }while(strcmp(choice,"y")==0);

          return 0;


          The block inside the do{...} will execute at least once, then the user will be asked to input a char (y/n) to decide whether to continue or not.
          The strcmp(string1,string2) compares two strings and returns 0 if they are equal, so if the user chose "y", the strcmp will return 0 and the do-while will be executed again.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433211%2fhow-to-make-a-c-program-loop-back-to-starting-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Just wrap your code into an infinite loop (while(1) { /* Your code here*/ }):



            #include < stdio.h >

            int main() {
            int a, v, b, c, delt;
            float x1, x2;

            while (1) {
            printf("nIntroduceti cele 3 parametrii ecuatia: ");

            scanf("%d %d %d", & a, & b, & c);
            if (a != 0) {
            v = pow(b, 2);
            delt = v - (4 * a * c);

            if (delt >= 0) {

            delt = sqrt(delt);
            x1 = -(b + delt) / (2.0 * a);
            x2 = -(b - delt) / (2.0 * a);

            printf("nValoara lui x1 este: %f", x1);
            printf("n");
            printf("nValoara lui x2 este: %f", x2);

            } else {
            printf("Ecuatia nu are soluti! n");
            }

            } else if (a == 0) {
            printf("nBLACKHOLE");
            }
            }

            return 0;
            }





            share|improve this answer


























            • I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

              – Rami Raghfan
              Nov 22 '18 at 14:46











            • It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

              – terales
              Nov 22 '18 at 14:50
















            0














            Just wrap your code into an infinite loop (while(1) { /* Your code here*/ }):



            #include < stdio.h >

            int main() {
            int a, v, b, c, delt;
            float x1, x2;

            while (1) {
            printf("nIntroduceti cele 3 parametrii ecuatia: ");

            scanf("%d %d %d", & a, & b, & c);
            if (a != 0) {
            v = pow(b, 2);
            delt = v - (4 * a * c);

            if (delt >= 0) {

            delt = sqrt(delt);
            x1 = -(b + delt) / (2.0 * a);
            x2 = -(b - delt) / (2.0 * a);

            printf("nValoara lui x1 este: %f", x1);
            printf("n");
            printf("nValoara lui x2 este: %f", x2);

            } else {
            printf("Ecuatia nu are soluti! n");
            }

            } else if (a == 0) {
            printf("nBLACKHOLE");
            }
            }

            return 0;
            }





            share|improve this answer


























            • I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

              – Rami Raghfan
              Nov 22 '18 at 14:46











            • It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

              – terales
              Nov 22 '18 at 14:50














            0












            0








            0







            Just wrap your code into an infinite loop (while(1) { /* Your code here*/ }):



            #include < stdio.h >

            int main() {
            int a, v, b, c, delt;
            float x1, x2;

            while (1) {
            printf("nIntroduceti cele 3 parametrii ecuatia: ");

            scanf("%d %d %d", & a, & b, & c);
            if (a != 0) {
            v = pow(b, 2);
            delt = v - (4 * a * c);

            if (delt >= 0) {

            delt = sqrt(delt);
            x1 = -(b + delt) / (2.0 * a);
            x2 = -(b - delt) / (2.0 * a);

            printf("nValoara lui x1 este: %f", x1);
            printf("n");
            printf("nValoara lui x2 este: %f", x2);

            } else {
            printf("Ecuatia nu are soluti! n");
            }

            } else if (a == 0) {
            printf("nBLACKHOLE");
            }
            }

            return 0;
            }





            share|improve this answer















            Just wrap your code into an infinite loop (while(1) { /* Your code here*/ }):



            #include < stdio.h >

            int main() {
            int a, v, b, c, delt;
            float x1, x2;

            while (1) {
            printf("nIntroduceti cele 3 parametrii ecuatia: ");

            scanf("%d %d %d", & a, & b, & c);
            if (a != 0) {
            v = pow(b, 2);
            delt = v - (4 * a * c);

            if (delt >= 0) {

            delt = sqrt(delt);
            x1 = -(b + delt) / (2.0 * a);
            x2 = -(b - delt) / (2.0 * a);

            printf("nValoara lui x1 este: %f", x1);
            printf("n");
            printf("nValoara lui x2 este: %f", x2);

            } else {
            printf("Ecuatia nu are soluti! n");
            }

            } else if (a == 0) {
            printf("nBLACKHOLE");
            }
            }

            return 0;
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 22 '18 at 14:49

























            answered Nov 22 '18 at 14:41









            teralesterales

            1,7121526




            1,7121526













            • I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

              – Rami Raghfan
              Nov 22 '18 at 14:46











            • It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

              – terales
              Nov 22 '18 at 14:50



















            • I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

              – Rami Raghfan
              Nov 22 '18 at 14:46











            • It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

              – terales
              Nov 22 '18 at 14:50

















            I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

            – Rami Raghfan
            Nov 22 '18 at 14:46





            I see! So a formation of indents can do that? Will you be so kind to provide me with an in depth resource on using this?

            – Rami Raghfan
            Nov 22 '18 at 14:46













            It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

            – terales
            Nov 22 '18 at 14:50





            It's not about indentation (C doesn't care about it, but humans do). It's about adding an infinite loop, check an example I've added in the beginning and accept an answer if it was helpful :)

            – terales
            Nov 22 '18 at 14:50













            1














            You could wrap everything in a do-while loop and ask the user whether he wants to continue the execution or not, for example:



            int a,v,b,c,delt;
            float x1,x2;
            char choice;
            do{
            printf("nIntroduceti cele 3 parametrii ecuatia: ");
            scanf("%d %d %d", &a, &b, &c);
            if(a!=0)
            {
            v=pow(b, 2);
            delt = v-(4*a*c);

            if (delt>=0)
            {
            delt=sqrt(delt);
            x1=-(b+delt)/(2.0*a);
            x2=-(b-delt)/(2.0*a);

            printf("nValoara lui x1 este: %f", x1);
            printf("n");
            printf("nValoara lui x2 este: %f", x2);
            }
            else
            {
            printf("Ecuatia nu are soluti! n");
            }
            }
            else if(a==0)
            {
            printf("nBLACKHOLE");
            }
            printf("nEvaluate new equation?(y/n) ")
            scanf("%c",&choice)
            }while(strcmp(choice,"y")==0);

            return 0;


            The block inside the do{...} will execute at least once, then the user will be asked to input a char (y/n) to decide whether to continue or not.
            The strcmp(string1,string2) compares two strings and returns 0 if they are equal, so if the user chose "y", the strcmp will return 0 and the do-while will be executed again.






            share|improve this answer




























              1














              You could wrap everything in a do-while loop and ask the user whether he wants to continue the execution or not, for example:



              int a,v,b,c,delt;
              float x1,x2;
              char choice;
              do{
              printf("nIntroduceti cele 3 parametrii ecuatia: ");
              scanf("%d %d %d", &a, &b, &c);
              if(a!=0)
              {
              v=pow(b, 2);
              delt = v-(4*a*c);

              if (delt>=0)
              {
              delt=sqrt(delt);
              x1=-(b+delt)/(2.0*a);
              x2=-(b-delt)/(2.0*a);

              printf("nValoara lui x1 este: %f", x1);
              printf("n");
              printf("nValoara lui x2 este: %f", x2);
              }
              else
              {
              printf("Ecuatia nu are soluti! n");
              }
              }
              else if(a==0)
              {
              printf("nBLACKHOLE");
              }
              printf("nEvaluate new equation?(y/n) ")
              scanf("%c",&choice)
              }while(strcmp(choice,"y")==0);

              return 0;


              The block inside the do{...} will execute at least once, then the user will be asked to input a char (y/n) to decide whether to continue or not.
              The strcmp(string1,string2) compares two strings and returns 0 if they are equal, so if the user chose "y", the strcmp will return 0 and the do-while will be executed again.






              share|improve this answer


























                1












                1








                1







                You could wrap everything in a do-while loop and ask the user whether he wants to continue the execution or not, for example:



                int a,v,b,c,delt;
                float x1,x2;
                char choice;
                do{
                printf("nIntroduceti cele 3 parametrii ecuatia: ");
                scanf("%d %d %d", &a, &b, &c);
                if(a!=0)
                {
                v=pow(b, 2);
                delt = v-(4*a*c);

                if (delt>=0)
                {
                delt=sqrt(delt);
                x1=-(b+delt)/(2.0*a);
                x2=-(b-delt)/(2.0*a);

                printf("nValoara lui x1 este: %f", x1);
                printf("n");
                printf("nValoara lui x2 este: %f", x2);
                }
                else
                {
                printf("Ecuatia nu are soluti! n");
                }
                }
                else if(a==0)
                {
                printf("nBLACKHOLE");
                }
                printf("nEvaluate new equation?(y/n) ")
                scanf("%c",&choice)
                }while(strcmp(choice,"y")==0);

                return 0;


                The block inside the do{...} will execute at least once, then the user will be asked to input a char (y/n) to decide whether to continue or not.
                The strcmp(string1,string2) compares two strings and returns 0 if they are equal, so if the user chose "y", the strcmp will return 0 and the do-while will be executed again.






                share|improve this answer













                You could wrap everything in a do-while loop and ask the user whether he wants to continue the execution or not, for example:



                int a,v,b,c,delt;
                float x1,x2;
                char choice;
                do{
                printf("nIntroduceti cele 3 parametrii ecuatia: ");
                scanf("%d %d %d", &a, &b, &c);
                if(a!=0)
                {
                v=pow(b, 2);
                delt = v-(4*a*c);

                if (delt>=0)
                {
                delt=sqrt(delt);
                x1=-(b+delt)/(2.0*a);
                x2=-(b-delt)/(2.0*a);

                printf("nValoara lui x1 este: %f", x1);
                printf("n");
                printf("nValoara lui x2 este: %f", x2);
                }
                else
                {
                printf("Ecuatia nu are soluti! n");
                }
                }
                else if(a==0)
                {
                printf("nBLACKHOLE");
                }
                printf("nEvaluate new equation?(y/n) ")
                scanf("%c",&choice)
                }while(strcmp(choice,"y")==0);

                return 0;


                The block inside the do{...} will execute at least once, then the user will be asked to input a char (y/n) to decide whether to continue or not.
                The strcmp(string1,string2) compares two strings and returns 0 if they are equal, so if the user chose "y", the strcmp will return 0 and the do-while will be executed again.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 14:50









                DLMDLM

                584




                584






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433211%2fhow-to-make-a-c-program-loop-back-to-starting-function%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga