473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Coin Counting Help

10 New Member
Hey there i was wondering if someone can help me with my program. I thought i had it down...but i'm having some problems. Here's the assignment.

Write a C function named change() that accepts a floating point number of total coins and the addresses of the integer variables named quarters, dimes, nickels, and pennies. The function should determine the number of quarters, dimes, nickels, and pennies in the total coins number passed to it and write these values directly into the respective variables declared in its calling function using pointers.

Call the function change() from main() three times and print out the contents of the variables quarters, dimes, nickels, and pennies after each function return.

First Call--pass in the total value $1.88 and on return print the contents of the variables.

Second Call--pass in the total value .32 and on return print the contents of the variables.

Third Call--ask for a total value input from the keyboard and on return print the contents of the variables.

Output should look like:

TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies


and not:

TOTAL VALUE ENTERED: 1.88
7 quarters
18 dimes
37 nickels
188 pennies

Here's my code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. int main()
  4. {
  5.     void change (float);
  6.     float value;
  7.     int count, i;
  8.     printf("Enter the value you wish to count: ");
  9.     scanf("%d", count);
  10.     for (i = 0, i <= count, i++)
  11.     {
  12.         printf("Please enter the amount: ");
  13.         scanf("%f", value);
  14.     }
  15.     return 0;
  16. }
  17.  
  18.     void change (float x)
  19.     int quarters, dimes, nickles, pennies;
  20.     float value, store;
  21.     value = x;
  22.     store = x;
  23.  
  24.     while (value >= .25)
  25.     {
  26.           quarters ++;
  27.           value = value - .25;
  28.     }
  29.  
  30.     while (value >= .1)
  31.     {
  32.           dines ++;
  33.           value = value - .1:
  34.     }
  35.  
  36.     while (value >= .05)
  37.     {
  38.           nickels ++;
  39.           value = value - .05;
  40.     }
  41.  
  42.     while (value >= .01)
  43.     {
  44.           pennies ++;
  45.           value = value - .01;
  46.     }
  47.  
  48.     printf("The total value entered was: %f ", store);
  49.     printf("%d" quarters, quarters\n);
  50.     printf("%d" dimes, dimes\n);
  51.     printf("%d" nickles, nickles\n);
  52.     printf("%d" pennies, pennies\n);
  53. }
  54.  
I'm getting a slew of errors once i compile. if anyone can help it would be greatly appreciated. Thanks for your time :)
May 11 '07 #1
6 6555
sicarie
4,677 Recognized Expert Moderator Specialist
Are you getting error messages, or the "wrong" output you posted? If error messages, can you post them?
May 11 '07 #2
scruggsy
147 New Member
Expand|Select|Wrap|Line Numbers
  1. for (i = 0, i <= count, i++)
You'll get a redeclaration error here. Replace the commas with semicolons.
Expand|Select|Wrap|Line Numbers
  1. int quarters, dimes, nickles, pennies;
  2. float value, store;
  3. value = x;
  4. store = x;
  5.  
  6. while (value >= .25)
  7. {
  8. quarters ++;
  9. value = value - .25;
  10. }
quarters, dimes, nickles, and pennies should be initialized to 0 before you use them.
I assume your mismatched spelling of "dimes"/"dines" and "nickles"/"nickels" is just the result of typing the code up for the forums. If not, that's another source of errors.
May 11 '07 #3
karafire2003
10 New Member
Yes you are RIGHT, i did have some spelling differences between quarters, nickels, dimes, and pennies. hehehehe
here are some of the errors that i got after i corrected spelling and changed the commas to semicolons:
C:\Documents and Settings\T\Desktop\Work\Classes\assignments\WA-3\Coins.c In function `change':
20 C:\Documents and Settings\T\Desktop\Work\Classes\assignments\WA-3\Coins.c syntax error before "value"
48 C:\Documents and Settings\T\Desktop\Work\Classes\assignments\WA-3\Coins.c stray '\' in program
49 C:\Documents and Settings\T\Desktop\Work\Classes\assignments\WA-3\Coins.c stray '\' in program
50 C:\Documents and Settings\T\Desktop\Work\Classes\assignments\WA-3\Coins.c stray '\' in program
51 C:\Documents and Settings\T\Desktop\Work\Classes\assignments\WA-3\Coins.c stray '\' in program

that's it. changing the commas to semicolons cleared up a lot of the errors...thanks for the corretion :)
May 11 '07 #4
Ganon11
3,652 Recognized Expert Specialist
I think you are missing an opening '{' when starting your function.

The main thing I see here is not a syntax error, but rather a discontinuity between your program and the problem specification. Your function in supposed to be accepting 5 arguments - the float variable, x, as you have, and then the addresses of quarters, dimes, nickels, and pennies. This suggests to me that these variables should be declared in your main() and then passed by reference to the change() function. Right now, you declare and use them within your function.

If you move the variables back to the main(), you should also move your printf calls so that the output is done in main, also. change() should be assigning values to the variables only rather than displaying them.
May 11 '07 #5
karafire2003
10 New Member
i don't quite follow. you have to understand i'm totally clueless about programming.
May 12 '07 #6
Ganon11
3,652 Recognized Expert Specialist
Write a C function named change() that accepts a floating point number of total coins and the addresses of the integer variables named quarters, dimes, nickels, and pennies.
This is what your assignment says. Now let's take a look at your function header:

Expand|Select|Wrap|Line Numbers
  1. void change (float x)
Your function is only accepting one parameter - the "floating point number of total coins." But your assignment tells you to have four more variables - "the addresses of the integer variables named quarters, dimes, nickels, and pennies."

Do you know how to pass by reference?
May 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1637
by: Jon Monteleone | last post by:
Greetings, I posted a few days back and didnt get much of a response, so I figured I would post again with more detail. I am running gnome under fedora core 4. I want a kid to be able to drop a...
12
2831
by: DannyB | last post by:
I'm just learning Python. I've created a simple coin flipper program - here is the code: #Coin flipper import random heads = 0 tails = 0 counter = 0
3
16898
by: viewsonic | last post by:
Help, im a student that has to write a program for counting coins. Half of the program works but the other half doesn.t should have the following parameters. output is: Name Date total...
0
1532
by: coolindienc | last post by:
Honestly, I am totally lost about this program. I don't even know where to start. At first I thought I can ask a user to flip a coin. But then again one will get bored flipping coin fot 100 times....
5
3829
by: sallyk57 | last post by:
I have to make a program that would ask a user for their guess (heads or tails) and tells them if its correct or not then it has to ask the user if they want to play again. I figured out how to do...
6
6059
blackstormdragon
by: blackstormdragon | last post by:
I just started a C++ class and now we're doing loops and have to make a coin flipping program. Well here's mine: #include<iostream> #include<cstdlib> using namespace std; int flip(); void main...
3
2940
by: Jamie88 | last post by:
This program is for a machine wich gives out coins up to the value of £4.99 using the minimun number of coins, but i'm i really having trouble gettin this to work. Any help would really be...
8
24889
by: PAK11 | last post by:
This is what i have so far.......I need to add a function named coin to simulate a coin toss where heads is represented by a 1 and tails a 2. The outcome of the toss should be printed and the result...
0
1161
Chuncatty
by: Chuncatty | last post by:
How much does a Draped Bust coin fabricate cost? (Sorry for my Eng) I ask a beau to see if it's genuine he said it is, down repay a collage professor i met said so. It's in virtue word,...
0
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.