Thread: class assignment

  1. #1
    Registered User
    Join Date
    Mar 2018
    Posts
    1

    class assignment

    Hey I'd really appreciate some help on my homework assignment, I'm just beginning to learn loops and I can't figure out why it isn't working. I attached a screenshot of what the output it supposed to be, but when I run mine it outputs that the volume is 0 after 1082801280 regardless of what I enter into it. Any help would be great hopefully I'm not doing anything too dumb.

    Code:
    #define _CRT_SECURE_NO_WARNINGS
    #include  <stdio.h>
    
    
    int main(void)
    {
        //declare variables
        double time = 0;
        double water = 500;
        double watergain;
        double waterloss = 0;
        //opening statement
        
            printf("Please enter the additional gallons of water needed every hour: ");
            scanf("%d", &watergain);
            
            while (water > 100) {
                printf("The volume is %d after %d hours\n", water, time++);
                waterloss = (10 * water) / 100;
                water = water - waterloss + watergain;
            }
                
            
        
        system("pause");
        return (0);
    }
    Attached Images Attached Images class assignment-screenshot-1-jpg 

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    It's just the scanf and printf formats. %d is for decimal integers, just like %x is for hex integers, %o for octal, and %i is for scanf input that allows 0x1A2B notation for hex, 0123 (leading zero) notation for octal, and otherwise reads the input as decimal. In printf, %d and %i are identical (both output in decimal).

    %f is for float, %lf is for double (that's a lowercase L). With printf you can also use %f for double (floats are passed to printf as doubles anyway so %f and %lf are the same), but in scanf you must use %lf for double (scanf is passed a pointer and needs to know the size of the object).
    Last edited by john.c; 03-16-2018 at 04:05 PM.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a class assignment
    By EonsNearby in forum C++ Programming
    Replies: 19
    Last Post: 03-20-2011, 09:36 AM
  2. Need help with a class assignment
    By EonsNearby in forum C++ Programming
    Replies: 36
    Last Post: 03-17-2011, 04:04 PM
  3. class assignment, help!
    By TriKri in forum C++ Programming
    Replies: 7
    Last Post: 10-06-2007, 08:17 AM
  4. Class assignment
    By tmnismo91 in forum C Programming
    Replies: 18
    Last Post: 06-19-2007, 07:00 PM
  5. Another class assignment, please help.
    By WinterInChicago in forum C++ Programming
    Replies: 16
    Last Post: 11-09-2006, 11:51 AM

Tags for this Thread