473,651 Members | 2,792 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 6572
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\Desk top\Work\Classe s\assignments\W A-3\Coins.c In function `change':
20 C:\Documents and Settings\T\Desk top\Work\Classe s\assignments\W A-3\Coins.c syntax error before "value"
48 C:\Documents and Settings\T\Desk top\Work\Classe s\assignments\W A-3\Coins.c stray '\' in program
49 C:\Documents and Settings\T\Desk top\Work\Classe s\assignments\W A-3\Coins.c stray '\' in program
50 C:\Documents and Settings\T\Desk top\Work\Classe s\assignments\W A-3\Coins.c stray '\' in program
51 C:\Documents and Settings\T\Desk top\Work\Classe s\assignments\W A-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
1665
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 quarter into a coin slot and get 15 minutes of time on an account that has "restricted" Internet access via the firefox web browser. We are experimenting with different ways to allow kids to safely surf the web during school hours while...
12
2841
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
16925
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 number of coins number of quarters number of dimes
0
1542
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. How do I get a computer to flip coin and get result? Any ideas??? Any help will be greatly appreciated greatly!!!!!!!! Andy
5
3838
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 this but the part that i am stuck on is how to print a summary at the end of this program tracking how many wins and how many losses. import cs1.Keyboard; public class CoinToss6 { public static void main(String args) { ...
6
6068
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 () { int coin, counter, tails = 0, heads = 0; for (counter = 1; counter <= 100; counter++)
3
2954
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 appreciated #include <iostream> #include <fstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath>
8
24911
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 should be return to the main program. I'm having trouble figuring it out, can anyone please help? #include <iostream> using namespace std; # include <ctime> int coin();
0
1167
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, well-grounded the top formerly larboard piece is kinda scratched. How much do you meditate on it's worth? pic of coin is here: http://coindad.com/coin/Cent_1803_F.jpg" http://coindad.com/coin/Cent_1803_F.jpg
0
8352
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7297
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.