Thread: Help, please

  1. #1
    Registered User
    Join Date
    Jul 2022
    Posts
    4

    Help, please

    Hey everyone, I am 100% brand new to C programming. I currently am stuck on a few programs I am trying to create for practice. The program runs perfectly, but the output doesn't reflect the answer I am trying to get. It continues to put out 0.00 as the final answer.
    Attached Images Attached Images Help, please-snipcprog-jpg 

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,128
    Please post your code as plain text in Code Blocks, not as an unclear image.

  3. #3
    Registered User
    Join Date
    Jul 2022
    Posts
    4
    Quote Originally Posted by rstanley View Post
    Please post your code as plain text in Code Blocks, not as an unclear image.
    Sorry about that. The photo was clear on my computer.
    Code:
    #include <stdio.h> 
    
    
    int main () //start of program
    
    
    {
     float tax=.08, total, sale; //signifies variables
    
    
        
    printf("Please enter the sales amount."); //output to user to enter sales amount
        
            
    scanf("%f",&sale);    //User inputs total sale amount
        
        
    total=sale*tax;    //Assignment expression to calculate sales tax
        
        
    printf("Your total sales tax is:%.2f\n", &total); //final output from calculations
        
    
    
    return 0;          //end of program
    }
    Last edited by Salem; 07-29-2022 at 10:58 PM. Reason: Added code tags

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    Compile with warnings enabled.
    Code:
    $ gcc -Wall foo.c
    foo.c: In function ‘main’:
    foo.c:21:36: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float *’ [-Wformat=]
       21 | printf("Your total sales tax is:%.2f\n", &total); //final output from calculations
          |                                 ~~~^     ~~~~~~
          |                                    |     |
          |                                    |     float *
          |                                    double
    Your final printf is wrong, you don't normally have & in your printf statements unless you're using the %p format.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,128
    Quote Originally Posted by downsidelove View Post
    Sorry about that. The photo was clear on my computer.
    You can't compile, test, and debug a fuzzy image!

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    It's the whacked font that makes 'o' and '0' look identical which isn't helping either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jul 2022
    Posts
    4
    Thank you! @Salem
    Last edited by downsidelove; 07-30-2022 at 03:09 PM.

Popular pages Recent additions subscribe to a feed

Tags for this Thread