Need assistance--plz!

This is a discussion on Need assistance--plz! within the C++ Programming forums, part of the General Programming Boards category; I'm working on a calculator program. It is suppose to accumulate the operations performed. Acceptable characters are +, -, *, ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    5

    Need assistance--plz!

    I'm working on a calculator program. It is suppose to accumulate the operations performed. Acceptable characters are +, -, *, %, /, =, and !

    Where I run into problems is printing the results when the characters input are = or !.

    The following is my code (less the statement for = & ! (I keep getting an endless loop).

    I'm still learning, so bear with me for any mistakes within the code.

    Any help would be appreciated. Thank you!

    Code:
    #include <iostream.h>
    int   result;    // the result of the calculations 
    char  oper_char; // the user-specified operator 
    int   value;     // value specified after the operator 
    main()
    {
        result = 0; // initialize the result 
     
        // loop forever (or until break reached)
        while (1) {
            cout << "Result: " << result << '\n';
            cout << "Enter operator and number: ";
     
            cin >> oper_char;
     
            if (oper_char == '!')
                break;
     
            cin >> value;
            if (oper_char == '+') {
                result += value;
            } else if (oper_char == '-') {
                result -= value;
            } else if (oper_char == '*') {
                result *= value;
    		} else if (oper_char == '%') {
    			result %= value;
            } else if (oper_char == '/') {
                if (value == 0) {
                    cout << "Error: Divide by zero\n";
                    cout << "   operation ignored\n";
                } else
                    result /= value;
            } else {
                cout << "Unknown operator " << oper_char << '\n';
            }
        }
        return (0);
    }

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    make

    while (1) {


    while(oper_char != '!') {

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. Newbie c programmer need assistance plz...
    By Nexus-ZERO in forum C Programming
    Replies: 17
    Last Post: 12-27-2007, 04:05 PM
  4. Assistance needed --Plz
    By Newbie96 in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2003, 07:44 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:44 AM

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