Thread: char identifier output problem

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    16

    Question char identifier output problem

    hi,
    i'm having trouble with my char identifier in this code, i copied it below, i can't think of what is wrong. when i run it the characters that are returned are different then what i entered at the prompt (i put in ECL and the output was CBA);. If you can see anything wrong with my code please respond.
    thanks!
    emily
    Code:
    #include <stdio.h>
    
    int main()
    {
    
            char first, middle, last;
            int pennies, nickles;
            int dimes, quarters;
            int dollars;
            int change;
            int total_dollars;
            int total_cents;
    
            printf ("Please enter 3 initials:");
            scanf ("%c%c%c", &first, &middle, &last);
            printf ("\n%c%c%c, please enter your coin information.\n");
    
            printf ("Number of one dollar coins:");
            scanf ("%d", &dollars);
            printf ("Number of quarters:");
            scanf ("%d", &quarters);
            printf ("Number of dimes:");
            scanf ("%d", &dimes);
            printf ("Number of nickles:");
            scanf ("%d", &nickles);
            printf ("Number of pennies:");
            scanf ("%d", &pennies);
    
            total_cents = 100*dollars + 25*quarters + 10*dimes + 5*nickles + pennies;
    
            total_dollars = total_cents / 100;
            change = total_cents % 100;
    
            printf ("\n\n%c%c%c Coin Credit");
            printf ("\nDollars:%d", total_dollars);
            printf ("\nChange:%d change", change);
            printf ("\nThank you for shopping at Robocop2 SuperFoods.  Please present your hall pass.\n");
    
           return(0);
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    printf ("\n%c%c%c, please enter your coin information.\n");
    Do you believe this prints any character variables before the ", please"? Why?

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    16
    hi, if i made a mistake please let me know, i'm pretty new. i don't quite understand what you are asking me.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, you can interpret it that way. My post looks like a question (question marks and everything), smells like a question; you wouldn't go too far wrong to treat it as a question. Do you believe that the code I quoted from your program prints any character variables? Why do you think so? I'll add an extra question: if you believe it prints character variables, which character variables do you think it prints and why?

    (Now I don't necessarily expect you to post answers, but the process of answering those questions may be enlightening.)

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    16
    hi, thank you. you gave me a different way to think about it. all fixed.
    emily

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Problem with char and char*
    By chris1985 in forum C Programming
    Replies: 1
    Last Post: 05-08-2005, 11:44 AM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

Tags for this Thread