Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,105 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,698 people online right now. Registration is fast and FREE... Join Now!




Making Change

 
Reply to this topicStart new topic

Making Change, C program for making change

Theteamdrunk
3 Oct, 2007 - 11:34 AM
Post #1

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 18


My Contributions
So I'm really new at this, i have an idea of whats going on, but my compiler keeps giving me errors. I need help please. Basically, I need to enter an amount of money and have the program spit out the amount in change that it is. For example $2.27, the program should say 8 quarters, 2 dimes, 1 nickels and 2 pennies.

CODE

#include<stdio.h>

int main()

{
    int num;
    int pennies;
    int quarters;
    int dimes;
    int nickels;
    
    printf("Enter the dollar amount: \n");
    scanf("%d", &num);
    
     quarters = (num % quarters);

     dimes = num - (quarters*.25) % .1;
    
     nickels = num - (quarters*.25) - (dimes*.10) % 0.05;

     pennies = num - (quarters*.25) - (dimes*.10) - (nickels*.05) / pennies;


     printf ("Your amount contain the following");
     printf ("quarters:   " ,quarters);
     printf ("dimes:    " ,dimes);
     printf ("nickels:    " ,nickels);
     printf ("pennies:    " ,pennies);

     scanf("%d", &num);
     return 0;
       }


Any help would be appreciated.
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Making Change
3 Oct, 2007 - 11:53 AM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
the % operator only accepts ints as arguments. use pennies instead of dollars as your unit of currency.

-jjh

(p.s. the terminating code tag requires a forward slash, not a backslash. thanks for trying to use them, though)

This post has been edited by jjhaag: 3 Oct, 2007 - 11:54 AM
User is offlineProfile CardPM
+Quote Post

Theteamdrunk
RE: Making Change
3 Oct, 2007 - 12:20 PM
Post #3

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 18


My Contributions
so your saying instead of using .25 to use 25?

And I am not sure that I understand the int % thing. Can you explain?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Making Change
3 Oct, 2007 - 12:25 PM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,441



Thanked: 64 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
int can't hold decimals, you'll need to declare float or double.

This question comes up all the time(it's a common homework assignment), check the snippets, tutorials or previous posts.
User is online!Profile CardPM
+Quote Post

Theteamdrunk
RE: Making Change
3 Oct, 2007 - 01:04 PM
Post #5

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 18


My Contributions
thanks for the snide comment at the end douche. I looked at a lot of that stuff, most of it was C++. And I said before I am new to this stuff.
User is offlineProfile CardPM
+Quote Post

Theteamdrunk
RE: Making Change
3 Oct, 2007 - 04:09 PM
Post #6

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 18


My Contributions
I changed the int to float and my compiler came up with the error

"invalid operands of 'float' and 'float' to binary 'operator%'

When I tried double I got the error

"invalid operands of 'double' and 'double' to binary 'operator%'
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Making Change
3 Oct, 2007 - 04:35 PM
Post #7

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
no2pencil's comments were not snide - he was directing you to a source of information that may help you with your problem. after your response to a good faith effort to help you out, you may find that some members will be less than willing to provide assistance.

-jjh
User is offlineProfile CardPM
+Quote Post

Theteamdrunk
RE: Making Change
3 Oct, 2007 - 05:19 PM
Post #8

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 18


My Contributions
I looked at the snippets and the tutorials and a good portion of the previous posts and the ones that I found were in C++. I am not familiar with that, let alone the C that I am trying to figure out. I did not mean to offend anyone, but I am frustrated with this programming stuff.
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Making Change
3 Oct, 2007 - 05:36 PM
Post #9

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
i can understand frustration, but take a baseball bat to your monitor if you want to vent - don't take it out on someone who's tried to help you.

two functions you may need are fmod(numerator, denominator) and floor(value). they are available in the math.h header. fmod is the floating point function version of %. and floor rounds a number to the next integertowards negative infinity- useful if you want to keep the integer value of a floating point number while dropping everything past the decimal place.

-jjh
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:13PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month