| | |
Currency Converer (Need help with this)
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
A few more improvements to the fixed code.
The %.2f thing won't work for scanf, it's only for formatting output in printf. For printf, currency converters usually stop at the 0s for precision, so %g is a better choice than %f. %f will print the maximum precision all of the time, even if it's all 0s.
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> /* constants should be centralized */ #define PESO 13.170025 #define USD 0.07593 void clear(FILE *strm) { int c; do c = getchar(); while (c != '\n' && c != EOF); } int main() { /* double is usually a better choice than float */ double amount; int choice; /* long strings can be broken down to avoid multiple printfs */ /* if you don't print '\n', flush the stream */ printf("1) USD to PESO\n" "2) PESO to USD\n" "> "); fflush(stdout); /* check input for failure */ if (scanf("%d", &choice) != 1) { fputs("Bad input\n", stderr); return EXIT_FAILURE; } /* consolidate code to avoid redundancy */ /* if you don't print '\n', flush the stream */ printf("Enter the amount: "); fflush(stdout); /* check input for failure */ if (scanf("%lf", &amount) != 1) { fputs("Bad input\n", stderr); return EXIT_FAILURE; } if (choice == 1) { printf("%gUSD == %gPESO\n", amount, amount * PESO); } else { printf("%gPESO == %gUSD\n", amount, amount * USD); } clear(stdin); fputs("Press <Enter> to continue...", stderr); getchar(); return EXIT_SUCCESS; }
•
•
•
•
Also there is no need for the %.2f thing, %f will do.
-Tommy (For Great Justice!) Gunn
If the code is already there, you might as well help make it better and hope the guy learns something instead of sitting on your **** waiting for him to fail at life.
-Tommy (For Great Justice!) Gunn
>If the code is already there, you might as well help make it better and hope the
>guy learns something instead of sitting on your **** waiting for him to fail at life.
Why not nicely pack in a parcel with automatic installers and send him on his postal address with a Project website built?

Not blaming you actually, but it was the post before yours which was the culprit.
>guy learns something instead of sitting on your **** waiting for him to fail at life.
Why not nicely pack in a parcel with automatic installers and send him on his postal address with a Project website built?

Not blaming you actually, but it was the post before yours which was the culprit.
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
•
•
•
•
No, you blurted it out in response to Hiroshe's first suggestion without waiting for the OP to ask more questions.
•
•
•
•
Why not nicely pack in a parcel with automatic installers and send him on his postal address with a Project website built?
•
•
•
•
If they're still confused, then your "advanced" answer is high and dry in the land of "huh?, wtf"
-Tommy (For Great Justice!) Gunn
•
•
•
•
If the code is already there, you might as well help make it better and hope the guy learns something instead of sitting on your **** waiting for him to fail at life.
you post your code there, and wait for someone to make it better and hope some guy doesn't expect you to actually learn something, and you can just sit on your ass waiting for handouts all your life
•
•
•
•
And he can ask questions. That's how it works in most places. See something you don't understand, ask about it, get an answer, and learn.
and where are these "most places" of which you speak? The ones where people ask questions to get answers? Because it sure isn't here.
DoEds
Newbie Poster
Posts: 1
.
Last edited by jephthah; Jul 1st, 2009 at 2:20 pm.
Enough, people. The facts are
1) fixed code should not have been posted by anyone other than the OP
2) fixed code should not have been improved by anyone unless the OP posted correct code in the first place.
3) People who expect the world to give them a free ride deserve the right to fail, and do not deserve the right to pass.
Now stop the flaming and get back on track.
1) fixed code should not have been posted by anyone other than the OP
2) fixed code should not have been improved by anyone unless the OP posted correct code in the first place.
3) People who expect the world to give them a free ride deserve the right to fail, and do not deserve the right to pass.
Now stop the flaming and get back on track.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Jun 2009
Posts: 32
Reputation:
Solved Threads: 0
Oh man i got it working thanks a lot...
Sorry for very late reply i was so busy at the moment...
I can only surf to internet during night time...
This so cool...It's my first time to join programming community (well, daniweb is the first one)...And i got lot of replies...
I'm gonna love this site...
I really had a hard time in programming 'coz our instructor was giving first an activity before he explains everything...
That's really kinda odd >,<
Sorry for very late reply i was so busy at the moment...
I can only surf to internet during night time...
This so cool...It's my first time to join programming community (well, daniweb is the first one)...And i got lot of replies...
I'm gonna love this site...
I really had a hard time in programming 'coz our instructor was giving first an activity before he explains everything...
That's really kinda odd >,<
![]() |
Similar Threads
- currency interest program need help coding it further (C++)
- currency convertor (JavaScript / DHTML / AJAX)
- Formatting in Currency (Visual Basic 4 / 5 / 6)
Other Threads in the C Forum
- Previous Thread: Cant run the code using gcc
- Next Thread: Reading A File
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api append array arrays bash binarysearch centimeter char character cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic execv feet fflush fgets file floatingpointvalidation fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide infiniteloop initialization interest intmain() kilometer lazy license linked linkedlist linux linuxsegmentationfault list match matrix meter microsoft multi mysql oddnumber odf open openwebfoundation pattern pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scheduling segmentationfault send shape single socketprogramming spoonfeeding stack standard strchr string strings structures suggestions system test testautomation unix urboc user voidmain() win32api windows.h






