C programming help

Discussion in 'Computer Games and General Discussion' started by Feels Good Man, Oct 6, 2010.

Oct 6, 2010

C programming help by Feels Good Man at 5:07 AM (608 Views / 0 Likes) 4 replies

  1. Feels Good Man
    OP

    Member Feels Good Man GBAtemp Advanced Maniac

    Joined:
    Apr 15, 2007
    Messages:
    1,643
    Country:
    Canada
    CODE#include

    main()
    {
    double factor;
    double resizer;
    double final;
    int end = 1;

    printf("RECIPE RESIZER\n");
    printf("Enter the factor:");
    scanf("%lf", &factor);

    while(end ==1)
    {
    printf("Enter an amount (or 0 to stop):");
    scanf("%lf", &resizer);

    if (resizer > 0)
    {
    final = (factor*resizer);
    printf("You should use %.2lf instead\n", &final);
    }

    else if (resizer ==0)
    {
    printf("Closing program...\n");
    end++;
    }


    //final = 0;

    }
    system("pause");
    }


    http://pastebin.com/9gVE5bXJ

    Can someone tell me why it doesn't calculate? >__> I have another program with the same problem
     
  2. trumpet-205

    Member trumpet-205 Embrace the darkness within

    Joined:
    Jan 14, 2009
    Messages:
    4,363
    Country:
    United States
    Umm.....

    I noticed that you use system("PAUSE") in your programming. You need to include stdlib.h for that function.
    You are better off using getchar(), explained in this website: http://www.gidnetwork.com/b-61.html

    It has been long time since I done any programming. I'm setting up an IDE right now. I'll run your program and see what is wrong with it.
     
  3. Joe88

    Member Joe88 [λ]

    Joined:
    Jan 6, 2008
    Messages:
    11,187
    Location:
    NYC
    Country:
    United States
    printf("You should use %.2lf instead\n", &final);

    take out the "&" next to final

    it works now
     
  4. Feels Good Man
    OP

    Member Feels Good Man GBAtemp Advanced Maniac

    Joined:
    Apr 15, 2007
    Messages:
    1,643
    Country:
    Canada
    Oh my gyad it works.

    Awesome. Thanks!

    I have to read over this book again -__-
     
  5. trumpet-205

    Member trumpet-205 Embrace the darkness within

    Joined:
    Jan 14, 2009
    Messages:
    4,363
    Country:
    United States
    Another thing I want to point out is that you use else if.

    "else if" is only used when you have 3 or more conditions. If you have 2 conditions then you use if/else or 2 if.
     

Share This Page