Like Tree1Likes
  • 1 Post By stahta01

Having issues with if statements... Please help.

This is a discussion on Having issues with if statements... Please help. within the C Programming forums, part of the General Programming Boards category; So, I'm making a program where the user makes a choice between 5 algorithms, so far it compiles just fine, ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    Albuquerque, New Mexico, United States
    Posts
    7

    Exclamation Having issues with if statements... Please help.

    So, I'm making a program where the user makes a choice between 5 algorithms, so far it compiles just fine, and the components do the math perfectly, but I can't get the statements to execute just one chosen algorithm.
    I tried a switch statement at first but I thought this would be easier, but instead of running just one component of the code, it just files through all the code sections, can anyone help?

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
            double x,y,z,a,fusum,presum; //values for case 1
            double choice;
            printf("\nPlease choose which calculation to preform accordning to the number infront of the option:\n-------------------------------------------\n1.Single Payment Compount Ammount Formula.\n2.Single Payment Present Worth Formula.\n3.Uniform Payment Series A.\n4.Uniform Payment Series B.\n5.Uniform Payment Series C.\n\n");
            scanf("%lf",&choice);
                if (choice<=5)      { printf("You chose:%1.0f\n",choice); }
                else if (choice>5)  {printf("Input not an option, please try again\n"); }    
            if(choice==1);
            {
                printf("Enter APR percent in decimal form, then number of years.\n");     //requesting inputs
                scanf("%lf",&x);                             //assigning inputs
                scanf("%lf",&y);                            // to be used for the APR and years passed
                z = pow(x+1,y);                         //assigning number to be multiplied by current payment
                printf("Enter current ammount sum:");                     //requesting current payment
                scanf("%lf",&a);
                fusum = z * a;
                printf( "%3.3f percent APR over %1.0f years, with current ammount of %.2f dollars is %.2f\n",x,y,a,fusum);
                //expressing outputs along with terating base and power to eliminate mistakes.
            }
            if (choice==2);
            {
                printf("Entire APR percent in decimal form, then number of years.\n");
                scanf("%lf",&x); //assigning inputs
                scanf("%lf",&y); //to be used for the APR and years passed
                z = pow(x+1,-y); //assigning number to be multiplied by current payment
                printf("Enter future ammount wanted:");
                scanf("%lf",&a);
                presum = z * a;
                printf("With %3.3f percent APR over %1.0f years, to get %.2f dollars a deposit of %.2f will be required\n",z,y,a,presum);
            }
                        
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,506
    Get rid of ";" after ")".
    Tim S.

    Code:
    if(choice==1);
    {
    sseppala likes this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User
    Join Date
    Feb 2012
    Location
    Albuquerque, New Mexico, United States
    Posts
    7
    Wow, thanks, I feel stupid now for not seeing that xD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with if statements
    By mjskolly in forum C Programming
    Replies: 11
    Last Post: 08-17-2011, 11:33 PM
  2. Little help - If statements
    By mrben2k9 in forum C Programming
    Replies: 1
    Last Post: 11-09-2009, 05:41 PM
  3. If statements
    By DJ_Steve in forum C Programming
    Replies: 12
    Last Post: 08-13-2009, 12:43 PM
  4. my if statements
    By rodrigorules in forum C++ Programming
    Replies: 2
    Last Post: 11-29-2005, 11:47 AM
  5. Help with IF statements
    By boontune in forum C++ Programming
    Replies: 12
    Last Post: 01-22-2003, 07:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21