Thread: Resistance Calculator , my resistor values are wrong at the end for calculation2&3

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2020
    Posts
    2

    Resistance Calculator , my resistor values are wrong at the end for calculation2&3

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    int main()
    
    
    
    
    
    
    {
        char c1, c2, c3, c4, c5, c6, choicenew;
        int choiceRs;
        float RsP,Rs3,Rs2,Rs1,choiceSP3,choiceSP2,choiceSP1,choiceSP=0,choiceRs3,choiceRs2,choiceRs1,rone3,rone2,rone1,rtwo3,rtwo2,rtwo1,rthree3,rthree2,rthree1;
        printf("-----------------------------------------------------------------------------------------------------------------------\n");
        printf("Project Done By:123\nProject Title: Resistance Calculator\n");
        printf("-----------------------------------------------------------------------------------------------------------------------\n");
        start:
        printf("Enter 6 secret Number(PASSWORD): \n");
        c1 = getch(); putchar('*');
        c2 = getch(); putchar('*');
        c3 = getch(); putchar('*');
        c4 = getch(); putchar('*');
        c5 = getch(); putchar('*');
        c6 = getch(); putchar('*');
    
    
                 if (c1 == '1' && c2 == '2' && c3 == '3' && c4 == '4' && c5 == '5' && c6 == '6')
            {
                printf("\nWelcome to Equivalent Resistance Calculator!!! \n");
    
    
                printf("\nYou're advised to Calculate 3 times for proper Summary\n");
            }
            else
            {
              printf("\n You have entered wrong Password!\n");
              goto start;
    
    
    
    
            }
            /* printf("\nSshhh!! Secret letters you typed are: %c%c%c%c%c%C", c1, c2, c3, c4, c5, c6);*/
    
    
    
    
    
    
    
    
    select:
             printf("\nSelect Either Series or Parallel Circuit\n");
             printf("\nPress 1 for Series Circuit \nPress 2 for Parallel Circuit\n ");
    
    
     {
    
    
            int choiceSP, i;
            float r[3] , RsS = 0;
            start2:
            scanf("%d",&choiceSP);
    
    
            choiceSP3=choiceSP2;
            choiceSP2=choiceSP1;
            choiceSP1=choiceSP;
    
    
    
    
    switch (choiceSP)
    
    
    {
    case 1 :
            printf("You have chosen *Series Circuit* ");
    
    
    {
             printf("\nEnter the number of Resistors in your circuit:\n ");
             printf("\nPress 1 for 2 Resistors \nPress 2 for 3 Resistors \n ");
    
    
                     int choiceRs;
                     start3:
                     scanf("%d",&choiceRs);
    
    
                     choiceRs3=choiceRs2;
                     choiceRs2=choiceRs1;
                     choiceRs1=choiceRs;
    
    
    
    
    switch (choiceRs)
    
    
                    {
                    case 1 :
                      printf("\nYou have chosen *2 Resistors*");
    {
                      {
    
    
                        printf("\nEnter Value of Each Resistor (in Ohm) : \n");
    
    
                        for (i = 0; i < 2; i++)
                          {
                            printf("\nR%d : ", i + 1);
                            scanf("%f", &r[i]);
                           rone3=rone2;
                           rone2=rone1;
                           rone1=r[0];
                           rtwo3=rtwo2;
                           rtwo2=rtwo1;
                           rtwo1=r[1];
                           rthree3=rthree2;
                           rthree2=rthree1;
                           rthree1=r[2];
                          }
    
    
                        for (i = 0; i < 2; i++)
                        {
                        RsS = RsS + r[i];
                        }
    
    
                        printf("\nEquivalent Series Resistance = %.4f Ohm", RsS);
    
    
                                                                    Rs3=Rs2;
                                                                    Rs2=Rs1;
                                                                    Rs1=RsS;
                        getch();
                        system("CLS");
    YN1 :
    {
           printf("\nDo you want to calculate a new one?\n");
           printf("\nPress Y for *Yes* and N for *No* (End Program after showing summary)\n");
           fflush(stdin);
           scanf("%c", &choicenew);
    
    
           system("CLS");
      {
    
    
    
    
           if (choicenew == 'Y' || choicenew == 'y')
               {
                goto select;
               }
           else if (choicenew == 'N' || choicenew == 'n')
               {
                goto summary;
                break;
               }
           else if (choicenew != 'Y' || choicenew != 'y' || choicenew != 'N' || choicenew != 'n')
               {
                printf("Please choose either Y or N");
                goto YN1;
               }
    
    
      }
    
    
    }
                          }
                         break;
    
    
    
    
                        case 2 :
                        printf("\nYou have chosen *3 Resistors*");
                        {
                        {
                             printf("\nEnter Value of Each Resistor (in Ohm)  : \n");
    
    
                             for (i = 0; i < 3; i++)
                           {
                            printf("\nR%d : ", i + 1);
                            scanf("%f", &r[i]);
    
    
                          rone3=rone2;
                           rone2=rone1;
                           rone1=r[0];
                           rtwo3=rtwo2;
                           rtwo2=rtwo1;
                           rtwo1=r[1];
                           rthree3=rthree2;
                           rthree2=rthree1;
                           rthree1=r[2];
    
    
                           }
                           for (i = 0; i < 3; i++)
                           {
                           RsS = RsS + r[i];
                           }
    
    
                        printf("\nEquivalent Series Resistance = %.4f Ohm", RsS);
    
    
                                                                          Rs3=Rs2;
                                                                          Rs2=Rs1;
                                                                          Rs1=RsS;
    
    
                        getch();
                        system("CLS");
    
    
    YN2 :
     {
          printf("\nDo you want to calculate a new one?\n");
          printf("\nPress Y for *Yes* and *N* for No (End Program after showing summary) \n");
          fflush(stdin);
          scanf("%c", &choicenew);
          system("CLS");
          if (choicenew == 'Y' || choicenew == 'y')
             {
              goto select;
             }
          else if (choicenew == 'N' || choicenew == 'n')
             {
              goto summary;
              break;
             }
          else
             {
              printf("Please choose either Y or N");
              goto YN2;
             }
    
    
     }
    
    
                            }
                                }
    
    
    break;
    default:
    printf("Sorry you are only allowed to choose either 2 or 3 resistors\n");
    
    
    goto start3;
    break;
    
    
    }
    
    
                                }
                                break;
    case 2 :
                   printf("You have chosen *Parallel Circuit*");
                   float RsP = 0, invRsP = 0;
                {
                  printf("\nEnter the number of Resistors in your circuit:\n ");
                  printf("\nPress 1 for 2 Resistors \nPress 2 for 3 Resistors \n ");
    
    
                    int choiceRs;
                    start4:
                    scanf("%d",&choiceRs);
                     choiceRs3=choiceRs2;
                     choiceRs2=choiceRs1;
                     choiceRs1=choiceRs;
    
    
    switch (choiceRs)
    
    
    
    
    
    
    {
        case 1 :
        printf("\nYou have chosen *2 Resistors*");
        /*float r[10];*/
    
    
     {
         {
         printf("\nEnter Value of Each Resistor (in Ohm)  : n");
         for (i = 0; i < 2; i++)
         {
         printf("\n R%d : ", i + 1);
         scanf("%f", &r[i]);
           rone3=rone2;
                           rone2=rone1;
                           rone1=r[0];
                           rtwo3=rtwo2;
                           rtwo2=rtwo1;
                           rtwo1=r[1];
                           rthree3=rthree2;
                           rthree2=rthree1;
                           rthree1=r[2];
         }
         for (i = 0; i < 2; i++)
         {
         invRsP+=(1.0/r[i]);
         }
         RsP=(1.0/invRsP);
         }
    
    
         printf("\nEquivalent Parallel Resistance = %.4f Ohm", RsP);
    
    
                                                            Rs3=Rs2;
                                                            Rs2=Rs1;
                                                            Rs1=RsP;
    
    
           getch();
           system("CLS");
    YN3:
    {
    
    
    
    
        printf("\nDo you want to calculate a new one?\n");
        printf("\nPress Y for *Yes* and N for *No* (End Program after showing summary)\n");
        fflush(stdin);
        scanf("%c", &choicenew);
        system("CLS");
        if (choicenew == 'Y' || choicenew == 'y')
        {
         goto select;
        }
        else if (choicenew == 'N' || choicenew == 'n')
        {
         goto summary;
         break;
        }
        else
         {
           printf("Please choose either Y or N");
           goto YN3;
         }
    }
    }
    break;
                case 2 :
                  printf("\nYou have chosen *3 Resistors*");
    {
            {
                 printf("\nEnter Value of Each Resistor (in Ohm) : \n");
                 for (i = 0; i < 3; i++)
                {
                 printf("\n R%d : ", i + 1);
                 scanf("%f", &r[i]);
    
    
                 rone3=rone2;
                           rone2=rone1;
                           rone1=r[0];
                           rtwo3=rtwo2;
                           rtwo2=rtwo1;
                           rtwo1=r[1];
                           rthree3=rthree2;
                           rthree2=rthree1;
                           rthree1=r[2];
                }
                for (i = 0; i < 3; i++)
                {
                 invRsP+=(1.0/r[i]);
                }
                RsP=(1.0/invRsP);
            }
    
    
            printf("\nEquivalent Parallel Resistance = %.4f Ohm", RsP);
    
    
                                                                Rs3=Rs2;
                                                                Rs2=Rs1;
                                                                Rs1=RsP;
                getch();
                system("CLS");
    YN4:
    {
           printf("Do you want to calculate a new one?");
           printf("\nPress Y for *Yes* and N for *No* (End Program after showing summary)\n");
           fflush(stdin);
           scanf("%c", &choicenew);
           system("CLS");
           if (choicenew == 'Y' || choicenew == 'y')
          {
          goto select;
          }
          else if (choicenew == 'N' || choicenew == 'n')
          {
           goto summary;
           break;
          }
          else
          {
           printf("Please choose either Y or N");
           goto YN4;
          }
    
    
    }
    }
    
    
           break;
    default:
    printf("Sorry you are only allowed to choose either 2 or 3 resistors\n");
    goto start4;
    break;
    
    
    }
    }
           default:
           printf("Sorry please choose either 1 or 2 \n");
           goto start2;
           break;
    }
    
    
    summary:
    
    
        system("COLOR CF");
    
    
        printf("---------------------------------------------------------------------------------------------------------------------");
        printf("\nTake Note :");
        printf("\n\nCircuit type:\n1 = Series Circuit &\n2 = Parallel Circuit\n\n");
        printf("\nCalculation 1 is the latest while Calculation 3 was the earliest");
        printf("\n---------------------------------------------------------------------------------------------------------------------\n");
    
    
        printf("\nCalculation 1 : Equivalent Resistance = %.4f Ohm You chose Circuit type %.f  and %.f Resistors  \nR1=%.f, R2=%.f, R3=%.f\n",Rs1,choiceSP1,choiceRs1 + 1, rone1, rtwo1, rthree1);
        printf("\nCalculation 2 : Equivalent Resistance = %.4f Ohm You chose Circuit type %.f  and %.f Resistors  \nR1=%.f, R2=%.f, R3=%.f\n",Rs2,choiceSP2,choiceRs2 + 1, rone2, rtwo2, rthree2);
        printf("\nCalculation 3 : Equivalent Resistance = %.4f Ohm You chose Circuit type %.f  and %.f Resistors  \nR1=%.f, R2=%.f, R3=%.f\n",Rs3,choiceSP3,choiceRs3 + 1, rone3, rtwo3, rthree3);
        printf("\n*********************************************************************************************************************\n");
    
    
        printf("                                                THANK YOU!!!!                                                            ");
    
    
        printf("*********************************************************************************************************************");
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    } }
    Last edited by PsychoBandit; 02-10-2020 at 07:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My calculator in Dividing seems wrong I think
    By YaZao in forum C Programming
    Replies: 3
    Last Post: 07-27-2015, 08:09 PM
  2. Help! Calculator Not Working...What is wrong?
    By usernamed in forum C++ Programming
    Replies: 7
    Last Post: 08-08-2013, 10:52 PM
  3. write() and read() int values from socket returning wrong values.
    By Premjith P S in forum Linux Programming
    Replies: 8
    Last Post: 11-29-2012, 02:59 PM
  4. Resistor Color Decoder for a 6 band resistor
    By nivoca in forum C Programming
    Replies: 2
    Last Post: 06-25-2011, 12:44 PM
  5. What's wrong with my calculator?
    By andrewmin in forum C Programming
    Replies: 3
    Last Post: 09-08-2010, 02:30 PM

Tags for this Thread