Thread: Digits...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    5

    Digits...

    So I am only really just starting out down the line of learning how to program in C, and I am trying to create a program that reads input in a certain way. Specifically, I want my program to only read the last X (2) digits that the user inputs, and WHEN it reads the X number of digits, I want it to subtract a set number FROM these digits to find its input.

    Any help?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Show us the code you've started with.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    5
    Right now it's still concept, that's the whole problem I assume.

    What I am trying to do is basically a "change" procedure. I want somebody to enter a total (say 21.45) and have the program give back a minimal amount of change. I can define all of the variables on paper just fine, but when it comes right down to it, the program gets extremely wordy when it approaches smaller and smaller values.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    5
    A quick rundown of how it is "wordy:"

    pen = (tot - ((twe * 2000) + (te * 1000) + (fiv * 500) + (wun * 100) + (qua * 25) + (dim * 10) + (nick * 5))) / 1;

    that's my penny value right now.

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    What do you expect of us then?
    Mainframe assembler programmer by trade. C coder when I can.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    5
    I guess my big question was a means of shortening. When I get up to the more complex programs, I don't want to be using the same old method of long definitions for my variables, as I can only assume that things like that would leave that much more room for an error in syntax to occur. For that purpose, I was wondering of there were any ways of making the variable (pen) only read, say, the final 2 digits so that the formula could boil down to at least the simple (tot - ((qua * 25) + (dim * 10) + (nick * 5))) if even that.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And what does this have to do with reading the last two digits input?

    Do you want to read in an integer number of dollars and an integer number of cents?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Murk View Post
    I guess my big question was a means of shortening. When I get up to the more complex programs, I don't want to be using the same old method of long definitions for my variables, as I can only assume that things like that would leave that much more room for an error in syntax to occur. For that purpose, I was wondering of there were any ways of making the variable (pen) only read, say, the final 2 digits so that the formula could boil down to at least the simple (tot - ((qua * 25) + (dim * 10) + (nick * 5))) if even that.
    This has nothing to do with "reading the last two digits" and a lot to do with "calculating values in a reasonable way". There's no reason to always be subtracting each of the previous amounts of change handed out each time; have another variable of change_I_havent_handed_out_yet and update that variable every time you hand out quarters or dimes or nickels or whatever.

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    5
    Quote Originally Posted by tabstop View Post
    This has nothing to do with "reading the last two digits" and a lot to do with "calculating values in a reasonable way". There's no reason to always be subtracting each of the previous amounts of change handed out each time; have another variable of change_I_havent_handed_out_yet and update that variable every time you hand out quarters or dimes or nickels or whatever.

    Actually, I am going to try that one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. decimal to number if digits in different bases
    By jorgejags in forum C Programming
    Replies: 21
    Last Post: 09-24-2008, 12:55 PM
  2. reverse a number digits
    By tootoo in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2007, 11:24 AM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 11:39 AM
  4. Hex digits stored in char array.
    By Kevinmun in forum C Programming
    Replies: 8
    Last Post: 11-18-2005, 04:05 PM
  5. Odd/Even Digits in a Number-Help!
    By ProgrammingDlux in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2002, 10:39 PM