Back | Reverse | Quick Reply | Post Reply |

Basic C Programming
Link | by りんーちゃん on 2008-06-14 10:20:25 (edited 2008-08-03 03:21:42)
How to:
Write a program that computes for the least number of 100, 50, 20, 10, 5, 1, 0.5, 0.25, 0.10, 0.05, & 0.01 bills and coins equivalent to a given amount (assumed positive, max of 999.99, and assumed max of 2 digits in the decimal part).

edit:

here's what I did.
it's still buggy though, what's wrong with it?
C O D E :
main() { float fAmount; int nAmt, nAmou; int nHun, nFif, nTwe, nTen, nFive, nOne; int nCfif, nCtwe, nCten, nCfive, nCone; printf("Please enter the amount in pesos: "); scanf("%f", &fAmount); nAmou = fAmount / 1; nHun = nAmou / 100; nFif = nAmou % 100 / 50; nTwe = nAmou % 100 % 50 / 20; nTen = nAmou % 100 % 50 % 20 / 10; nFive = nAmou % 100 % 50 % 20 % 10 / 5; nOne = nAmou % 5; nAmt = fAmount*100; nCfif = nAmt % 100 / 50; nCtwe = nAmt % 100 % 50 / 25; nCten = nAmt % 100 % 50 % 25 / 10; nCfive = nAmt % 100 % 50 % 25 % 10 / 5; nCone = nAmt % 5; printf("no. of 100 peso bills = %dn", nHun); printf("no. of 50 peso bills = %dn", nFif); printf("no. of 20 peso bills = %dn", nTwe); printf("no. of 10 peso coins = %dn", nTen); printf("no. of 5 peso coins = %dn", nFive); printf("no. of 1 peso coins = %dn", nOne); printf("no. of 50 centavo coins = %dn", nCfif); printf("no. of 25 centavo coins = %dn", nCtwe); printf("no. of 10 centavo coins = %dn", nCten); printf("no. of 5 centavo coins = %dn", nCfive); printf("no. of 1 centavo coins = %d", nCone); }


O U T P U T :
 


-----

*fixed*
problem solved. :]
solution:
fAmount → double.


      
  m y . L i F E . i . t r a d e . i n . f o r . y o u r . P A i N .

Re: Basic C Programming
Link | by h4xordude on 2008-07-08 12:47:31
This seems to be a simple error.... judging from the fact that the 100 peso bills part outputs the right number (or am I reading the objective wrong?) it seems that the problem has something to do with all of the mod division you're doing (the %'s). I think in this case when it divides the numbers it gives a decimal so you may need to make the variables double rather than int...

And just to play it safe I'd use parentheses on the division lines just to make sure it's doing the operations in the right order, though I realize that's probably not what's causing THIS problem.

Beware the quiet people, You don't know their intentions
(small signatures are sooo much cooler since they don't annoy people trying to read through posts!)

Re: Basic C Programming
Link | by りんーちゃん on 2008-08-01 08:13:01
wh0opz~! :O sorry, I solved this problem long ago. :/
there was nothing wrong with the integer values.

Solution: the float (fAmount) should be declared and scanned as double. XP
⇑ some kind of C programming bug. o_O

I have another question though:
Programmed Animation:
I know it involves loops and time delay. But I know absolutely nothing about time delay. o__O
Care to explain please? :)

* I plan to animate using only 2 functions to serve as my frames.
Is that possible? D:


      
  m y . L i F E . i . t r a d e . i n . f o r . y o u r . P A i N .

Re: Basic C Programming
Link | by on 2008-08-03 00:08:53
I now currently just start to learn c++ programming...
Did senpai all think that it is an easy course?
I had difficulty understand d concept of pre and post increment operator,write a prompt line n understanding d #include concept..

i glad if someone would teach me..

COOL...

Re: Basic C Programming
Link | by on 2008-08-03 02:39:44
this C program my friends study it(the computer gifted) but i don't know any of the XD


Re: Basic C Programming
Link | by on 2008-08-03 03:03:56
i remmber having this on my computer classes last year o.o" pfft it was so hard! plus the teacher didnt explain the basics to us well!
c++ is terrible T___T


Re: Basic C Programming
Link | by Lanster on 2008-08-03 03:25:48
Hi, I also remember having this classes last year.

Umm, for information :
programmed animation can be made by visual c++,
u can make time delay by using for();

for example ==> for(x=0;x<=10000;x++);

I use c++ console for the example.
Etto, it will be better if you didn't use variable that confusing

For 2 digit in decimal parts :
Change %d ==>%0.2f

and if you write int nAmt, then don't use %d, but use %i
and since it use decimal value, then you can change int to float



post increment : you do increment after that line
pre increment : you do increment in that line

The system will do Increment first, then do the other iterations

#include : just a dll library, some function need a particular library to be used

Hmm, I hope I can help you again later *bow*.
Bye^^.

Reinforce

Re: Basic C Programming
Link | by りんーちゃん on 2008-08-03 03:46:49
since I included <conio.h> (I use a DJGPP compiler)
I was thinking I could use usleep() or delay() for the time intervals. :)


      
  m y . L i F E . i . t r a d e . i n . f o r . y o u r . P A i N .

Re: Basic C Programming
Link | by on 2008-08-27 22:08:11
is anyone knows how to differentiate the usage of if, else and switch, break function in c++ programme.
I found tat both look like same..
What it means when v use both function together in a programme?
Thanks..i hope my ques solved..

COOL...

Re: Basic C Programming
Link | by lianass on 2023-10-24 03:29:42
Lately I have become very interested in programming. And especially the question of how to code a social media app https://www.programmingassignment.net/blog/how-to-create-a-social-network-app/ I couldn’t figure it out for a long time until specialists could. It’s good that now there is an opportunity to turn to specialists.

Re: Basic C Programming
Link | by kimondo on 2023-11-02 04:09:10
Hi. If you want to learn how to manage your finances effectively, you should check out https://pocketguard.com/savings-goals/ . It talks about an app that provides indispensable tools to achieve your financial goals. I myself apply these recommendations and see positive results.

Re: Basic C Programming
Link | by altin on 2024-09-12 21:32:31 (edited 2024-09-13 04:02:42)
Basic C programming lays a strong foundation cox internet for understanding computer science principles. With its straightforward syntax and powerful capabilities, C helps beginners grasp key concepts like variables, loops, and functions. Mastering these fundamentals paves the way for more advanced topics and languages. Its efficiency and control over system resources make C an enduring choice for both learning and practical applications

Back | Reverse | Quick Reply | Post Reply |

Copyright 2000-2025 Gendou | Terms of Use | Page loaded in 0.0017 seconds at 2025-05-31 06:10:12