Thread: Code does not jump to next printf (Coding Noobie)

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    2

    Code does not jump to next printf (Coding Noobie)

    I am writing a simple calculator that doubles the amount of cents that are inputted. However I am having a little bit of trouble because the first input if not jumping to the the next "printf" when I press enter. The solution is probably simple but I have no idea. Thanks!
    Code does not jump to next printf (Coding Noobie)-wtf-pngCode does not jump to next printf (Coding Noobie)-wtf-code-png

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    In the future, please post your actual code in code tags, not a screen shot of your code.

    Code:
        scanf("%d%",&pen);
    Get rid of that extra % after "%d" in each of your "scanf()" calls.

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    2
    Thank you very much!

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You're welcome. As a courtesy, I rewrote your program exactly as you had it (filling in the missing code) and compiled it. This is the code I compiled, and the compiler warnings I got:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int pen, nick, dim, quart, total;
    
        printf("Hawk jents by Me\n");
        printf("\nEnter number of Pennies (0-100): ");
        scanf("%d%",&pen);
        printf("\nEnter number of Nickels (0-20): ");
        scanf("%d%",&nick);
        printf("\nEnter number of Dimes (0-10): ");
        scanf("%d%",&dim);
        printf("\nEnter number of Quarters (0-4): ");
        scanf("%d%",&quart);
        total = ((pen * 1) + (nick * 5) + (dim * 10) + (quart * 25) ) * 2;
        printf("\n\nTotal Hawk Jents = %d",total);
        printf("\n\nThanks for using Hawk Jents Calculator!");
    
        return 0;
    }
    
    
    /*
    main.c||In function 'main':|
    main.c|9|warning: spurious trailing '%' in format|
    main.c|11|warning: spurious trailing '%' in format|
    main.c|13|warning: spurious trailing '%' in format|
    main.c|15|warning: spurious trailing '%' in format|
    ||=== Build finished: 0 errors, 4 warnings ===|
    */
    These warnings should have been a clue for you to locate where the problem might have been. If your compiler didn't mention any warnings, then you need to increase your compiler warnings.

    Also, just a minor comment: Variable names should clearly state their purpose. You came close, but I would recommend not truncating words that are already short (e.g. "penny", "nickel", "dime", "quarter").

    Otherwise, good work!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noobie Code Help
    By DobbyQuack in forum C Programming
    Replies: 4
    Last Post: 06-05-2013, 08:53 PM
  2. C Coding Help: Unreachable Code
    By sammells in forum C Programming
    Replies: 15
    Last Post: 09-02-2012, 01:07 AM
  3. DirectShow code - long night of coding
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 03-27-2006, 10:50 AM
  4. printf+gets inside of code
    By tomas.ra in forum C Programming
    Replies: 7
    Last Post: 11-01-2005, 10:58 PM
  5. Replies: 3
    Last Post: 03-27-2004, 12:15 PM

Tags for this Thread