1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <cstdlib>
#include <iostream>
using namespace std;
float a,c,n,m;
char b,d;
inline float addizione(float a, float c){ //Function +
return m=a+c;
}
inline float sottrazione(float a, float c){ //Function -
return m=a-c;
}
inline float divisione(float a, float c){ //Function /
return m=a/c;
}
inline float moltiplicazione(float a, float c){ //Function *
return m=a*c;
}
int main()
{
cout << "This calculator will loop, to start a new equation, input n for new \nIgnore the nx, x represents any number, and keep on using it like before" << endl;
LOOP1:
cin >> a; // insert first integer
LOOP:
cin >> b; // insert +-/*
cin >> c; // insert second integer
cout << a;
cout << b;
cout << c;
if(b=='+'){
n=addizione(a,c);
cout << "=" << n << "; \n";
a=n;
}
else if(b=='-'){
n=sottrazione(a,c);
cout << "=" << n << "; \n";
a=n;
}
else if(b=='/'){
n=divisione(a,c);
cout << "=" << n << "; \n";
a=n;
}
else if(b=='*'){
n=moltiplicazione(a,c);
cout << "=" << n << "; \n";
a=n;
}
if(b=='n'){
goto LOOP1;
}
if(b=='+'){
goto LOOP;
}
if(b=='-'){
goto LOOP;
}
if(b=='*'){
goto LOOP;
}
if(b=='/'){
goto LOOP;
}
system("pause");
return 0;
}
|