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: -
-
#include <stdio.h>
-
int main()
-
{
-
void change (float);
-
float value;
-
int count, i;
-
printf("Enter the value you wish to count: ");
-
scanf("%d", count);
-
for (i = 0, i <= count, i++)
-
{
-
printf("Please enter the amount: ");
-
scanf("%f", value);
-
}
-
return 0;
-
}
-
-
void change (float x)
-
int quarters, dimes, nickles, pennies;
-
float value, store;
-
value = x;
-
store = x;
-
-
while (value >= .25)
-
{
-
quarters ++;
-
value = value - .25;
-
}
-
-
while (value >= .1)
-
{
-
dines ++;
-
value = value - .1:
-
}
-
-
while (value >= .05)
-
{
-
nickels ++;
-
value = value - .05;
-
}
-
-
while (value >= .01)
-
{
-
pennies ++;
-
value = value - .01;
-
}
-
-
printf("The total value entered was: %f ", store);
-
printf("%d" quarters, quarters\n);
-
printf("%d" dimes, dimes\n);
-
printf("%d" nickles, nickles\n);
-
printf("%d" pennies, pennies\n);
-
}
-
I'm getting a slew of errors once i compile. if anyone can help it would be greatly appreciated. Thanks for your time :)
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?
- for (i = 0, i <= count, i++)
You'll get a redeclaration error here. Replace the commas with semicolons. - int quarters, dimes, nickles, pennies;
-
float value, store;
-
value = x;
-
store = x;
-
-
while (value >= .25)
-
{
-
quarters ++;
-
value = value - .25;
-
}
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.
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 :)
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.
i don't quite follow. you have to understand i'm totally clueless about programming.
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:
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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
|
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
|
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)
{
...
| |
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++)
|
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>
|
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();
|
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
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |