Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: implementation of a calculator #302

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added the possibility to make more operations
Depoul committed Oct 22, 2023
commit 27695b1e44ff3cc596e512548ba3f520c83e2c1b
47 changes: 29 additions & 18 deletions exercises/calculator.cpp
Original file line number Diff line number Diff line change
@@ -16,35 +16,34 @@ using namespace std;
#define EXIT_SUCCESS 0


float switchOp(int x, int a, int b){
float result;
float switchOp(int x, float a, float b){

switch(x){
case 1:{
cout << endl << "SUM = ";
result = a + b;
break;
return a + b;
}

case 2:{
cout << endl << "Difference = ";
result = a - b;
break;
return a - b;
}

case 3:{
cout << endl << "Multiplication = ";
result = a * b;
break;
return a - b;
}

case 4:{
cout << endl << "Division = ";
result = a / b;
break;
return a / b;
}

default:{
cerr << "Invalid operand.";
return 0;
}
}
return result;
}

void operations(float a, float b){
@@ -73,13 +72,25 @@ void operations(float a, float b){

int main(){

float a,b;
cout << "Insert the first number: ";
cin >> a;
cout << endl << "Insert second number: ";
cin >> b;

operations(a, b);
char response;

while(true){
float a,b;
cout << "Insert the first number: ";
cin >> a;
cout << endl << "Insert second number: ";
cin >> b;

operations(a, b);

do{
cout << "Do you want to make another operation? (Y/N): ";
cin >> response;
}while(toupper(response)!= 'Y' && toupper(response) != 'N');

if(toupper(response) == 'N'){
break;
}
}
return EXIT_SUCCESS;
}