Jump to content

Is anyone here any good at C programming


Recommended Posts

Well safe to say I'm not all too good at programming so I ask if someone can stear me in the right direction here.

I am writing a code for class to give change for a purchase I have all the change calculating programming done and working great, my problem is that we need to have a way to check to see if inputs are real. (ie can't pay for a 2.00 dollar charge with 1.00 or pay "a" for a 2.00 charge) does anyone know how I could read in my interger inputs and make sure they are actually intergers?

Any help in general will do, all i need is a nudge in the right direction

1349713160_rte.png
Link to comment
Share on other sites

you probably want double or decimal rather than integer if you are dealing with money. Also, won't it error if the input is anything different than the declared variable's data type?

i have done very little in C so it may not work that way.

 

F150:

Stock :(

 

2019 Harley Road Glide:

Amp: TM400Xad - 4 channel 400 watt

Processor: DSR1

Fairing (Front) 6.5s -MMats PA601cx

Lid (Rear) 6x9s -  TMS69

 

Link to comment
Share on other sites

I declared the change as a decimal. I needed the number of each coin as an interger cause you can't have 2.5 quarters lol

I'm really rusty at this, I know i could use it all as a single input as a string and check it for characters there but I don't remember how to do that as of right now

1349713160_rte.png
Link to comment
Share on other sites

Guest DC Power Kyle

If the change calculating is done and working great then you shouldn't have an issue with it giving you 2.5 quarters?

Is it just giving you coins as change or can it give you bills as well, (1, 5, 10, 20, 50, 100 dollars)?

Maybe write out in this thread your input(s) to the program and expected output(s) and you can unit test if you're familiar with that

Link to comment
Share on other sites

#include <stdio.h>


int main()

{

double owe,pay,change, negative;

int quarter = 0,dime = 0 ,nickle = 0 ,pennie = 0;

printf("How much did the product you want cost?\n");

scanf("%lf",&owe);

printf("How much money will you be paying?\n");

scanf("%lf",&pay);


if (pay < owe || owe < 0)

{

printf("I'm sorry you don't have enough money to pay for this item\n");

negative = -1*(pay-owe);

printf("You owe %.2f more\n",negative);

printf("Goodbye\n");

return 0;

}



printf("If this is true you will be paying %.2f for a product costing %.2f\n", pay, owe);

change=pay-owe;

printf("You will recieve %.2f in change\n",change);

while (change > 0.24)

{

quarter++;

change=change-0.25;

}

printf("%i:quarters\n",quarter);

while (change > 0.09)

{

dime++;

change=change-0.10;

}

printf("%i:dimes\n",dime);


while (change > 0.04)

{

nickle++;

change=change-0.05;

}

printf("%i:nickle\n",nickle);

printf("%.2f change\n", change);

if (change <0.04)

{

pennie++;

change=change - 0.01;

}

printf("%i:pennie\n",pennie);

return 0;

}

1349713160_rte.png
Link to comment
Share on other sites

Guest DC Power Kyle

if you're doing this to get it "working" that is so much hassle than it's really worth because you don't have tests to back up your programming that you're refactoring.

Either pick one or the other and stick with it or have tests to back it up.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...