4 Replies - 221 Views - Last Post: 26 February 2018 - 01:04 AM Rate Topic: -----

#1 michael55111   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-February 18

Change lab. How to input cost and then give amount, output change back

Posted 25 February 2018 - 10:06 PM

 

#include <stdio.h>
/* only make changes at the places shown below */
/* fill in an expression in place of the comment that says "...something..." */
/* add declarations or code between comments as directed */
/* do not remove the comments in green */
/* do not remove or change anything else, including this comment */
int main(void)
{
	double dcost, dtendered;
	int icost, itendered;
	int itwenties, itens, ifives, iones, iquarters, idimes, inickels, ipennies,
		change;

	/* add any additional variables between here -> */

	itwenties = 20.00;
	itens = 10.00;
	ifives = 5.00;
	iones = 1.00;
	iquarters = 0.25;
	idimes = 0.10;
	inickels = 0.05;
	ipennies = 0.01;

	/* <- and here*/

	scanf("%lf", &dcost);
	scanf("%lf", &dtendered);

	icost = (int)(&dcost) * 100;
	itendered = (int)(&dtendered) * 100;

	/* add code to calculate itwenties, itens, etc., between here -> */

	change = icost - itendered;

	itwenties = change % (20 * 100);

	/* <- and here */


	printf("%2d twenties\n", itwenties);
	printf("%2d tens\n", itens);
	printf("%2d fives\n", ifives);
	printf("%2d ones\n", iones);
	printf("%2d quarters\n", iquarters);
	printf("%2d dimes\n", idimes);
	printf("%2d nickels\n", inickels);
	printf("%2d pennies\n", ipennies);
	while (1) getchar();
	return 0;
}




I'm new to programming in general and can't seem to figure this out. can someone give me a little hint? The proffessor put the comment in to help but yet I still cannot for the life of me figure it out. I've been stuck on this lab for about 3 hours and it's driving me crazy.

Is This A Good Question/Topic? 0
  • +

Replies To: Change lab. How to input cost and then give amount, output change back

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6216
  • View blog
  • Posts: 21,454
  • Joined: 05-May 12

Re: Change lab. How to input cost and then give amount, output change back

Posted 25 February 2018 - 10:18 PM

View Postmichael55111, on 26 February 2018 - 12:06 AM, said:

The proffessor put the comment in to help but yet I still cannot for the life of me figure it out.

It must be late. I am not seeing any comment from the professor about how to solve the problem. All I am seeing are markers for where to put in your code. I am likely simply going blind. Can you tell me which one the comments are in?
Was This Post Helpful? 0
  • +
  • -

#3 michael55111   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-February 18

Re: Change lab. How to input cost and then give amount, output change back

Posted 25 February 2018 - 10:20 PM

View PostSkydiver, on 25 February 2018 - 10:18 PM, said:

View Postmichael55111, on 26 February 2018 - 12:06 AM, said:

The proffessor put the comment in to help but yet I still cannot for the life of me figure it out.

It must be late. I am not seeing any comment from the professor about how to solve the problem. All I am seeing are markers for where to put in your code. I am likely simply going blind. Can you tell me which one the comments are in?


Here's the actual assignment. I am NOT asking for you to do it for me obviously but I'm just really stuck.

Change LabWrite a C program that computes the minimum number of bills and coins needed to make change for a particular purchase. The program takes two input parameters. The first parameter is the cost of the item. The second parameter is the amount of money tendered to pay for the item. Both parameters are non-negative fixed-point numbers with 2 digits to the right of the decimal point. Please be sure to keep these parameters in the correct order. The same input files will be fed to every program, and if a particular program needs special attention, say, to reverse the input parameters, then it’s not good.It is guaranteed that the input is correct. That means that the amount of money tendered is guaranteed to be greater than or equal to the cost of the item. In the case that the input is not correct, it does not matter what happens when your program is run with that incorrect input. The program should be developed with a focus on the case in which the input is correct, and you may safely ignore all possibilities involving incorrect input. In other words: if the input is correct, then your program must produce the correct output.In this program, variables of type double are not allowed, with the exception of processing the input. There should be two variables of type double, one for the cost of the item, and one for the amount of money tendered. These two variables represent amounts of money in dollars, possibly with a fractional part. Each of these variables can be read in with a scanf with a format specifier of “%lf”. There should also be two variables of type int, one for the cost of the item in pennies, and one for the amount of money tendered in pennies. The cost of the item in pennies is calculated from the cost of the item in dollars as follows. First, multiply the cost of the item in dollars (a variable of type double) by 100.0 (a constant of type double). Then add a small amount, namely 0.000001 (a constant of type double). Finally, use an explicit cast operator, written “( int )” to cast the sum to an integer, which is assigned to the int variable for the cost of the item in pennies. Similarly, convert the amount of money tendered in dollar (a variable of type double) to a number of pennies (a variable of type int).Do not do anything else with the variables of type double. Once the amounts have been converted to pennies, the lives of the variables of type double are over. Do not declare any other variables of type double or use any other costants of type double. From this point on, everything is int.The output format should be as shown in the following example output:13 twenties 1 tens 0 fives 4 ones 2 quarters 1 dimes 0 nickels 3 pennies
That is, the number of bills or coins uses a “%2d” format.Your program should make use of integer division (/) and/or integer modulo (%). Do not attempt to use subtraction in place of the modulo operator.Please use the example program below as the starting point. Only make changes where shown. Fill in an expression where it says “...something...”. That is, replace the comment /* ...something... */ with your expression. Add declarations or code between comments as directed. Do not remove the comments that say to add your code between here and here. Do not remove or change anything else outside of the places you are supposed to fill in
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is online

  • blow up my boots
  • member icon

Reputation: 6549
  • View blog
  • Posts: 26,557
  • Joined: 12-December 12

Re: Change lab. How to input cost and then give amount, output change back

Posted 26 February 2018 - 12:11 AM

You have very detailed instructions. What in particular is confusing you?

Also, have you run the code? It looks like it is in a runnable state.
Was This Post Helpful? 0
  • +
  • -

#5 albert003   User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 494
  • Joined: 15-December 14

Re: Change lab. How to input cost and then give amount, output change back

Posted 26 February 2018 - 01:04 AM

I agree, the instructions you posted are detailed. What part is confusing you? What errors are you getting when you run the program?. What part do you not understand?.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1