Want to go beyond my assignment

This is a discussion on Want to go beyond my assignment within the C Programming forums, part of the General Programming Boards category; Hi folks, well I hope you all can help guide me in the right direction. I have an assignment for ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    MN
    Posts
    1

    Want to go beyond my assignment

    Hi folks, well I hope you all can help guide me in the right direction. I have an assignment for a C class that requires a function named change() that accepts a single precision numeber and the address of the integer variables named quarters,dimes, nickels, pennies. The function is supposed to determine the number of quarters, dimes, nickels and pennies in the number passed to it and write the values back into the respective variables in it's calling function.

    I am stuck on the syntax on how to take the input number and let it be broken down into the appropriate values asked for. Also I was wanting to write some additional code to randomly generate these values as a seperate function When entering a specific value at the start.

    Here is what i have so far, nothing fancy, not very clean, but I can't find any other resource right now.

    Code:
    // Change function.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "math.h"
    #include "stdio.h"
    
    
    int _tmain(int argc, _TCHAR* argv[]);
    int main()
    {
    	void change (float *, float *,float *,float *,float *);	
    	float total, quarters, dimes, nickels, pennies;
    
    	quarters = .25;
    	dimes = .10;
    	nickels = .05;
    	pennies = .01;
    
    	printf("Enter dollar amount to be converted into change\n\n");
    
    		scanf("%f", &total);
    
    	printf("\nThe number you entered is stored in a variable named \"total\"\n");
    	printf("The address of \"total\" will be %u\n\n", &total);
    	printf("Other variables named \"quarters\",\"dimes\",\"nickels\",and \"pennies\" will be stored\n");
    	printf("in the following addresses\n\n");
    	printf("quarters address = %u\n", quarters);
    	printf("dimes address    = %u\n", dimes);
    	printf("nickels address  = %u\n", nickels);
    	printf("pennies address  = %u\n", pennies);
    		
    		change(&total, &quarters, &dimes, &nickels, &pennies);
    
    	return 0;
    }
    void change(float *totalchange, float *quarters, float *nickels, float *dimes, float *pennies)
    {
    	printf("\nThe number you entered is %.2f\n\n", *totalchange);
    	printf("Quarters are worth %.2f cents\n", *quarters);
    	printf("Dimes are worth    %.2f cents\n", *dimes);
    	printf("Nickels are worth  %.2f cents\n", *nickels);
    	printf("Pennies are worth  %.2f cents\n\n", *pennies);
    	printf("A randmomly generated value of quarters, dimes, nickels and pennies is\n");
    	printf("displayed below totaling the amount you entered earlier\n\n");
    
    }
    Please if anyone has any feedback that will help, please e-mail me with soe feedback. I'm not looking for anyone to write the rest for me, but some good direction would be nice. Thanks to all who help.

    Toasty

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your amount of money is logically, a float. Your coin variables should all be integers unless you're really into hack sawing.

    The first rule of forums is "You ask on the forum, we answer on the forum."

    If you have a specific question, ask away. General "I'd like to do this", is not the way to go. Show us what you've tried, and what the program fails to do correctly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 07:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 02:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21