Aritmetic string

This is a discussion on Aritmetic string within the C++ Programming forums, part of the General Programming Boards category; someone please help im desperate. now that thats out of the way......... im taking my first C++ class and i ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    3

    Red face Aritmetic string

    someone please help im desperate.

    now that thats out of the way.........

    im taking my first C++ class and i have no idea how you
    would implement 9+8*5-(6+7) = sum

    basically i want to enter this string and press enter and it should give me an answer.

    i have really no c++ experience so if any of you can email me some code i would really appreciate it.

    ps i use visual c++ microsoft

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    im taking my first C++ class and i have no idea how you
    would implement 9+8*5-(6+7) = sum.
    Hence the term "learning process". We have no problem discussing ideas like this. But so far, your idea stinks...perhaps you should put some more thought into it.

    basically i want to enter this string and press enter and it should give me an answer.
    Odd. That's what we all want out of a program.

    i have really no c++ experience so if any of you can email me some code i would really appreciate it.
    Sure, post your code and I'll be glad to email it back to you.

    P.S. - We don't do your homework here.
    Code:
    #include <ip.hpp>

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Don't expect anyone around here to do it for you. If that's what you're looking for, try this site: http://www.wedoyourhomework.com
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    3
    #include <iostream.h>


    int main()
    {
    // local variables

    int First ;
    int Second ;
    char ch ;
    // print directions

    cout << "\nEnter a series of single-digit numbers " << endl
    << "each followed by an arithmetic operator." << endl
    << "Enter the = operator to to compute your result." << endl
    << endl ;



    cin >> First >> ch ;



    while ( ch != '=' )
    {
    cin >> Second ;
    switch ( ch )
    {
    case '+' :
    First = First + Second ;
    break ;
    case '-' :
    First = First - Second ;
    break ;
    case '*' :
    First = First * Second ;
    break ;
    case '/' :
    if ( Second != 0 )
    First = First / Second ;
    else
    cout << "Division by zero.\n" ;
    break ;
    default :
    cout << "Input error.\n" ; return 1 ;
    }
    cin >> ch ;
    }

    cout << "Result: " << First << endl << endl ;



    return 0 ;
    }


    i cant figure out how to put cos, tan, and sin, or brakets

  5. #5
    Lurker
    Guest
    You have at least one logic error, if you entered the equation:

    9+8*5

    the answer should be 49 (9+40 = 49), but with your calculation it will be 85 (17*5 = 85).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21