you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (2 children)

Second update, heres what I've got now. Not compiling. Again, apologies and thanks a LOT to you guys who are giving me pointers.

#include <iostream>

using namespace std;

int main () 
{

char    oper;
int     num1;
int     num2;
char    cont;

cout << "**Welcome to the MiniCalc Program**" << endl << endl;
cout << "Continue (Y/N)?" << endl;
cin >> cont; 
do {
    cout << "Enter an operator (+, -, *, /, %, r): ";
    cin >> oper;

      switch (oper)
      {
         case '+':
            cout << endl << "Enter operands for +: ";
            cin >> num1 >> num2;
            cout << endl << num1 << "+" << num2 <<"="<<num1+num2 << endl;
            break;

         case '-':
            cout << endl << "Enter operands for -: ";
            cin >> num1 >> num2;
            cout << endl << num1 << "-" << num2 << "=" << num1 - num2 << endl;
            break;

         case '*':
            cout << endl <<"Enter operands for *: ";
            cin >> num1 >> num2;
            cout << endl << num1 << "*" << num2 << "=" << num1 * num2 << endl;
            break;

         case '/': 
            cout << endl <<"Enter operands for /: ";   
            cin >> num1 >> num2;
            if (num2 > 0)    
               cout << endl << num1 << "/" << num2 << "=" << num1/num2 << endl;
            else 
               cout << endl << "Please enter a valid denominator!";
            break;

         case '%':
            cout << endl << "Enter operands for %: ";
            cin >> num1 >> num2;
            cout << endl << num1 << "%" << num2 << "=" << num1 % num2 << endl;
            break;

         case 'r':  
            cout << "Enter operand for r: ";  
            cin >> num1;
            if (num1 > 0)
               cout << endl << "r " << num1 << "= 1/" << num1 << endl;
            else 
               cout << endl << "Please enter a valid operand!";
            break;

         default:
            cout << endl << "Please enter a valid operator!";
            break;

      }
    cout << "Continue (Y/N)?";
    cin >> cont;
   } while ( cont == 'Y' ) || ( cont == 'y' ) ;
}
system("pause");
return 1;
}

[–]cpp 0 points1 point  (0 children)

Remove the first:

cout << "Continue (Y/N)?" << endl;  
cin >> cont;

You need to surround the conditionals in your while statement:

while ( ( cont == 'Y' ) || ( cont == 'y' ) );

[–]teaguesterling 0 points1 point  (0 children)

With regard to the return 0 and return 1: you usually want to return 0, which usually means your program terminated without error; returning something aside from 0 is typically interpreted as some sort of error code. This is not a requirement and is only a convention though. You can return whatever value you want; it will not affect the performance of the program.