C programming help

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

  1. Feels Good Man
    OP

    Feels Good Man GBAtemp Advanced Maniac

    Member
    1,643
    19
    Apr 15, 2007
    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

    trumpet-205 Embrace the darkness within

    Member
    4,363
    542
    Jan 14, 2009
    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

    Joe88 [λ]

    Member
    11,673
    2,955
    Jan 6, 2008
    United States
    NYC
    printf("You should use %.2lf instead\n", &final);

    take out the "&" next to final

    it works now
     
  4. Feels Good Man
    OP

    Feels Good Man GBAtemp Advanced Maniac

    Member
    1,643
    19
    Apr 15, 2007
    Canada
    Oh my gyad it works.

    Awesome. Thanks!

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

    trumpet-205 Embrace the darkness within

    Member
    4,363
    542
    Jan 14, 2009
    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.