vendredi 22 septembre 2017

Math Calculator without 2 operands in C++

The value starts from 0 and can then be calculated using any operand of Mathematics. The code compiles successfully but doesn't work. The terminal windows shows 'Abort', 'Retry' and 'Cancel'. The rule is that you cannot use 2 operands but just keep adding the previous number to present operand.

#include <iostream>
#include <cmath>

using namespace std;

void Input (double input);


int main()
{
double sign, input;

cout << "This program calculates any given number upto 1 decimal place using 
the following operators:" << endl;
cout << " '+' - Addition." << endl;
cout << " '-' - Subtraction" << endl;
cout << " '*' - Multiplication." << endl;
cout << " '^' - Root." << endl;
cout << " '/' - Division." << endl;

Input( input);


return 0;
}

void Input( double IN)
{
char q;
char sign;
int Val = 0.0;

cin >> sign >> IN;

while (IN != q) {

    if (sign = '-')
        Val -= IN;
    if (sign = '+')
        Val += IN;
    if (sign = '*')
        Val *= IN;
    if (sign = '/')
        Val /= IN;

    cout << endl << "Result so far is " << IN;

    IN++;
}
}

Aucun commentaire:

Enregistrer un commentaire