1. ## 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. Show us the code you've started with.

3. 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. 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. What do you expect of us then?

6. 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. 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. Originally Posted by Murk
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. Originally Posted by tabstop
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.