Thread: Homework :)

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    4

    Question Homework :)

    Ia m not from the US or the UK or any other country that has English as their native language, so please forgive me if i made any grammar errors.

    MY teacher gave me a task to do at home:
    I need to create a simple calculator that does the basic stuff like + - * /, but it also has to repsect the order of calculation; for ex. if I type 2+3*5-5 it will first do the * and then the + & -. And it mustn't do the operations 1 by 1 as they are inputed, it has to do the entire equasion at once so it must allow the input of more numbers and operations until the user hits the button = and when the user hits the button = the calc gives out the solution. I hope u all understood me.

    I kinda suck at programming so I'm asking any of you guys if you could help me in any way possible. I'm nopt asking for you to do the program for me i'm just asking if any1 had any ideas on how i could do this. but if any1 could find the spare time to write me the program i woul dbe forever grateful ))

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Your teacher wants you to write expression parser?
    You could use shunting yard algorithm.
    If you are not good at programming, I could guess it would be hard for you.

    >>but if any1 could find the spare time to write me the program i woul dbe forever grateful
    No, read homework policy.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    76
    I did this assignment about 3 weeks ago, are you using problem solving and program design using C and are in in Chapter 6? If so reading the chapters really helps, LOL.

    Anyway, I created two functions, one to scan user input which returned a number and operator (used pointers) and another was a switch case to perform the operation using the operator chosen in the other function. The 2nd function returned the calculations to main to be displayed. Main was a do while loop that calls the other 2 functions as long as operator q and number 0 weren't selceted. There is an if/else statement in the do while loop that either displays the value so far and continues or displays the value and quits.

    Good luck, I'm a newbie as well this one took me some time to get right and I had to ask a couple of questions here as well. However I always post my code so folks were glad to help.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    4
    Quote Originally Posted by Bayint Naung View Post
    >>but if any1 could find the spare time to write me the program i woul dbe forever grateful
    No, read homework policy.
    I'm sorry i didn't know there was a homework policy ill read it ASAP!

    Quote Originally Posted by dolfaniss View Post
    However I always post my code so folks were glad to help.
    Thanks alot now I'm gonna get an A!

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    76
    Quote Originally Posted by boksanns94 View Post
    I'm sorry i didn't know there was a homework policy ill read it ASAP!



    Thanks alot now I'm gonna get an A!
    OHHHH, you found it. I don't know if I posted the final product, don't remember but I'm sure it was close.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Homework plz!
    By mythassassin in forum C++ Programming
    Replies: 4
    Last Post: 10-16-2007, 03:07 PM
  2. Homework... help!
    By xMEGANx in forum C++ Programming
    Replies: 11
    Last Post: 10-15-2007, 05:36 AM
  3. Help with C++ Homework
    By TheTaoOfBill in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2007, 07:17 PM
  4. C++ Homework Help!!!!
    By bar5037 in forum C++ Programming
    Replies: 12
    Last Post: 10-01-2007, 01:21 PM
  5. ok, yes, I need help with my homework!
    By melee in forum C Programming
    Replies: 5
    Last Post: 09-22-2004, 07:42 AM