| | |
help with conversion calculator
![]() |
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Solved Threads: 0
this code to convert pounds to barbados dollars given a constant rate the price cannot go over $100 when i first run it and input a number under 100 it tells me that it is invalid and sometimes i get nothing at all. Can neone tell me why?
C Syntax (Toggle Plain Text)
/* This Program converts Pounds Sterling to Barbados Dollars*/ # include <stdio.h> int main () { float Pds, Bds; /* Declare Variables*/ const float Rate =3.75; printf("Enter the Price in Pounds Sterling\n"); /*Prompt User*/ scanf_s("%f", &Pds); while(Pds >100);/* finds illegal value*/ { printf("Error your price cannot be greater than $100\n"); printf("Please Enter another\n"); scanf_s("%f",&Pds); } Bds=Pds*Rate; printf("Price in Barbados Dollars=%.2f",Bds); return 0; }
stop using scanf() because it may corrupt the input buffer and leave keys in the keyboard buffer. use fgets() instead
C Syntax (Toggle Plain Text)
float num; char buf[16]; printf("blabla"); // get input from user fgets(buf,sizeof(buf),stdin); // convert to float num = atof(buf);
Last edited by Ancient Dragon; Oct 7th, 2006 at 9:38 am.
while ( Pds > 100 ) ; is equivalent to C Syntax (Toggle Plain Text)
while ( Pds > 100 ) { // sit back and enjoy baby }
Like Mr. Dragon said the variable which controls the run of your "While " loop never changes and so it goes on for infinity.
Last edited by ~s.o.s~; Oct 9th, 2006 at 2:07 pm.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- MC68000/..332 Calculator (Assembly)
- HJT analysis would be appreciated (Viruses, Spyware and other Nasties)
- Complex Number Calculator in C++ (C++)
- Java to C# Conversion (C#)
Other Threads in the C Forum
- Previous Thread: End of file controlled loop
- Next Thread: calculator program in C -help needed
| Thread Tools | Search this Thread |
* adobe api array asterisks binarysearch calculate changingto char character cm copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory feet fgets file floatingpointvalidation forloop frequency function givemetehcodez global grade gtkgcurlcompiling gtkwinlinux hacking highest histogram homework i/o infiniteloop input interest intmain() iso kernel keyboard kilometer km linked linkedlist linux looping loopinsideloop. lowest meter microsoft mqqueue mysql number oddnumber odf open openwebfoundation owf pdf performance posix power probleminc process programming pyramidusingturboccodes radix read recv recvblocked repetition research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard string suggestions systemcall threads turboc unix urboc user variable wab whythiscodecausesegmentationfault win32api windows.h windowsapi






