| | |
Simple Calculator
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 9
Reputation:
Solved Threads: 0
Write a calculator program that lets users enter a simple mathematic operation and display the results as in the sample output shown below (bold text indicates user input).
Calculate: 92+1
Result = Ninety Three
Calculate: 92, 000 + 1
Result = Ninety Two Thousand
Calculate: 92, 000.01 + 1
Result = Ninety Two Thousand and One Point Zero One
Calculate: 92, 000.01 * 1 + 1 / 1
Result = Ninety Two Thousand and One Point Zero One
Your program MUST at least be able to interpret the following operators:
• +
• -
• /
• *
• %
• >
• <
• >=
• <=
p/s:pls can someone help me solve this problem and i am currently using knoppix software to solve this problem..pls help me..thx..
Calculate: 92+1
Result = Ninety Three
Calculate: 92, 000 + 1
Result = Ninety Two Thousand
Calculate: 92, 000.01 + 1
Result = Ninety Two Thousand and One Point Zero One
Calculate: 92, 000.01 * 1 + 1 / 1
Result = Ninety Two Thousand and One Point Zero One
Your program MUST at least be able to interpret the following operators:
• +
• -
• /
• *
• %
• >
• <
• >=
• <=
p/s:pls can someone help me solve this problem and i am currently using knoppix software to solve this problem..pls help me..thx..
Last edited by mikedd; Aug 19th, 2008 at 1:29 pm. Reason: forget to mention about knoppix
You also forgot to read these as well
http://www.daniweb.com/forums/announcement118-2.html
http://www.daniweb.com/forums/thread78060.html
Now, which bit are you really stuck on?
http://www.daniweb.com/forums/announcement118-2.html
http://www.daniweb.com/forums/thread78060.html
Now, which bit are you really stuck on?
•
•
Join Date: Jul 2008
Posts: 14
Reputation:
Solved Threads: 3
If I was doing this I think I would use sprintf to convert the numeric result to a string then parse the characters building the words from it:
http://www.cplusplus.com/reference/c...o/sprintf.html
http://www.cplusplus.com/reference/c...o/sprintf.html
•
•
Join Date: Aug 2008
Posts: 9
Reputation:
Solved Threads: 0
c Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int invalid_operator = 0; char operator1; float number1, number2, result; printf( "Enter two numbers and an operator in the format\n" ); printf( "number1 operator number2\n" ); scanf( "%f %c %f", &number1, &operator1, &number2 ); switch ( operator1 ) { case '*' : result = number1 * number2; break; case '/' : result = number1 / number2; break; case '+' : result = number1 + number2; break; case '-' : result = number1 - number2; break; default : invalid_operator = 1; } switch ( invalid_operator ) { case 1 : printf( "Invalid operator.\n" ); break; default : printf( "%f %c %f is %f\n", number1, operator1, number2, result ); } return 0; }
Last edited by Ancient Dragon; Aug 20th, 2008 at 9:18 am. Reason: add code tags
•
•
Join Date: Jul 2008
Posts: 14
Reputation:
Solved Threads: 3
•
•
•
•
Originally Posted by me
If I was doing this I think I would use sprintf to convert the numeric result to a string then parse the characters building the words from it:
http://www.cplusplus.com/reference/c...o/sprintf.html
Last edited by mike_g; Aug 20th, 2008 at 9:44 am.
The following example-code will 'convert' an int into a char
A char and an int are both numbers, they just differ in the way us humans read them
ascii-table
c Syntax (Toggle Plain Text)
int number = 97; //97 is the ascii value of 'a' char character = (char)number; // "convert" it printf("%c", character);
A char and an int are both numbers, they just differ in the way us humans read them

ascii-table
![]() |
Similar Threads
- What is wrong? Trying to make a simple calculator in Tkinter. (Python)
- Help with scientific calculator (Visual Basic 4 / 5 / 6)
- calculator with password (C++)
- Java Simple calc (Java)
- Calculator project (C++)
- calculator (Java)
- calculator program (Java)
- need help for c++ calculator (C++)
- having problems to complete implement a simple calculator program in c (C)
- simple calculator help (Java)
Other Threads in the C Forum
- Previous Thread: please help me with pointer to structures
- Next Thread: greatest of three nos
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures student suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h






