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

Added retry feature for wrong option and new calculation #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
60 changes: 39 additions & 21 deletions Calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

using namespace std;

void Option();
int numOf,result=0,a;


void Retry ()
{
char retryOption;
cout<<"Want to calculate again? (y/n)";
cin>>retryOption;
if(retryOption == 'y' || retryOption == 'Y')
Option();
else
return;
}
void Add ()
{
int numOf,result=0,a;
Expand All @@ -13,13 +25,14 @@ void Add ()

for(int i=0 ; i<numOf ; i++)
{
cout<<"Enter num. \n";
cout<<"Enter num."<<i+1<<" \n";
cin>>a;

result+=a;
}

cout<<result<<endl;
cout<<"Result = "<<result<<endl;
Retry();

}
void Minus ()
Expand All @@ -31,13 +44,14 @@ void Minus ()

for(int i=0 ; i<numOf ; i++)
{
cout<<"Enter num. \n";
cout<<"Enter num."<<i+1<<" \n";
cin>>a;

result-=a;
}

cout<<result<<endl;
cout<<"Result = "<<result<<endl;
Retry();

}

Expand All @@ -50,13 +64,14 @@ void Multi ()

for(int i=0 ; i<numOf ; i++)
{
cout<<"Enter num. \n";
cout<<"Enter num."<<i+1<<" \n";
cin>>a;

result*=a;
}

cout<<result<<endl;
cout<<"Result = "<<result<<endl;
Retry();

}
void Divide ()
Expand All @@ -68,30 +83,20 @@ void Divide ()

for(int i=0 ; i<numOf ; i++)
{
cout<<"Enter num. \n";
cout<<"Enter num."<<i+1<<" \n";
cin>>a;

result/=a;
}

cout<<result<<endl;
cout<<"Result = "<<result<<endl;
Retry();

}

int main ()
void Option ()
{
int choose;

cout<<" ***** ******************\n";
cout<<" ***** * *\n";
cout<<" ***** * The Calculator *\n";
cout<<" ***** * *\n";
cout<<" ********* ******************\n";
cout<<" *******\n";
cout<<" *****\n";
cout<<" ***\n";
cout<<" *\n";

cout<<"\n*Choose the way you want:\n 1-Add.\n 2-Minus.\n 3-Multi.\n 4-Divide.\n";
cin>>choose;

Expand All @@ -102,9 +107,22 @@ int main ()
case 2: Minus(); break;
case 3: Multi(); break;
case 4: Divide(); break;
default: cout<<"Wrong number. \n"; break;
default: cout<<"Wrong number. \n"; Retry(); break;
}
}
int main ()
{
cout<<" ***** ******************\n";
cout<<" ***** * *\n";
cout<<" ***** * The Calculator *\n";
cout<<" ***** * *\n";
cout<<" ********* ******************\n";
cout<<" *******\n";
cout<<" *****\n";
cout<<" ***\n";
cout<<" *\n";

Option();
return 0;
}

Expand Down