Thread: math program

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Talking math program

    for my math program, how do i tell it to carry out the operations, for example if the user entered:
    3
    *
    9
    -
    2
    +
    5
    E(termination character)

    how do i tell it to do the multiplication, subtraction and so on? would i use a switch structure?
    like:
    switch ( operation ) {
    case '*':
    ??????????;
    break;

    is that right or should i do it differently?

    the numbers are stored as integers and the operations are char and both are stored in arrays.
    thank you.
    Last edited by awkeller; 10-13-2001 at 09:50 PM.

  2. #2
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    So far you sound like you're on the right track. Personally I'd use a switch statement with the operator as the conditional statement. So if the operator is +, you're sure to add. However, you'll have to add a bit more code if you want the different operators to have precedence, such as * being calculated before +. Since you're using arrays this would be easy, simply iterate through the array and do a test to find which operator has the highest precedence.

    But I'm guessing that this is far beyond what is required for your program and you'll only want to try it after getting the rest to work.
    pointer = NULL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math program help.
    By Deadlyaim in forum C++ Programming
    Replies: 2
    Last Post: 09-29-2006, 07:57 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM