Simple Calculator

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 9
Reputation: mikedd is an unknown quantity at this point 
Solved Threads: 0
mikedd mikedd is offline Offline
Newbie Poster

Simple Calculator

 
-1
  #1
Aug 19th, 2008
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..
Last edited by mikedd; Aug 19th, 2008 at 1:29 pm. Reason: forget to mention about knoppix
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Simple Calculator

 
0
  #2
Aug 19th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,669
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: Simple Calculator

 
0
  #3
Aug 19th, 2008
sure, sure. i've got nothing better to do than do your homework.

shall i also write your report, bind it, and mail it first class to your instructor?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: mikedd is an unknown quantity at this point 
Solved Threads: 0
mikedd mikedd is offline Offline
Newbie Poster

Re: Simple Calculator

 
0
  #4
Aug 20th, 2008
i do not know how to change the result into character..Can teach me?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Simple Calculator

 
1
  #5
Aug 20th, 2008
Consider this
23 = Twenty three
123 = One hundred and twenty three
123,000 = One hundred and twenty three thousand

So you need to think about (eventually)
- splitting into groups of 1000
- splitting hundreds from tens and units

But start simple, try to code up converting 1 to 99.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: mike_g is an unknown quantity at this point 
Solved Threads: 3
mike_g mike_g is offline Offline
Newbie Poster

Re: Simple Calculator

 
0
  #6
Aug 20th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: mikedd is an unknown quantity at this point 
Solved Threads: 0
mikedd mikedd is offline Offline
Newbie Poster

Re: Simple Calculator

 
0
  #7
Aug 20th, 2008
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int invalid_operator = 0;
  6. char operator1;
  7. float number1, number2, result;
  8.  
  9. printf( "Enter two numbers and an operator in the format\n" );
  10. printf( "number1 operator number2\n" );
  11. scanf( "%f %c %f", &number1, &operator1, &number2 );
  12.  
  13. switch ( operator1 ) {
  14. case '*' :
  15. result = number1 * number2;
  16. break;
  17. case '/' :
  18. result = number1 / number2;
  19. break;
  20. case '+' :
  21. result = number1 + number2;
  22. break;
  23. case '-' :
  24. result = number1 - number2;
  25. break;
  26. default :
  27. invalid_operator = 1;
  28. }
  29.  
  30. switch ( invalid_operator ) {
  31. case 1 :
  32. printf( "Invalid operator.\n" );
  33. break;
  34. default :
  35. printf( "%f %c %f is %f\n",
  36. number1, operator1, number2, result );
  37. }
  38.  
  39. return 0;
  40. }
p/s:said i hav done this programe..But i do not know how to make the calculated output into character.Can someone pls show me how to make it?
Last edited by Ancient Dragon; Aug 20th, 2008 at 9:18 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: mike_g is an unknown quantity at this point 
Solved Threads: 3
mike_g mike_g is offline Offline
Newbie Poster

Re: Simple Calculator

 
0
  #8
Aug 20th, 2008
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
Have you tried converting the result to a string yet? that should make a good first step.
Last edited by mike_g; Aug 20th, 2008 at 9:44 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: mikedd is an unknown quantity at this point 
Solved Threads: 0
mikedd mikedd is offline Offline
Newbie Poster

Re: Simple Calculator

 
0
  #9
Aug 21st, 2008
but the problem now is i do not even know how to convert a single integer into a character.can u pls at least show me how to convert an integer into a character?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,971
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Simple Calculator

 
0
  #10
Aug 21st, 2008
The following example-code will 'convert' an int into a char
  1. int number = 97; //97 is the ascii value of 'a'
  2. char character = (char)number; // "convert" it
  3. printf("%c", character);

A char and an int are both numbers, they just differ in the way us humans read them

ascii-table
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC