#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<cmath>
usingnamespace std;
int main ()
{
int loopcount=0;
int total=0;
int Total1=1;
char choice, choice1, choice2, choice3, choice4;
int Answer,x,y;
int NumbersAmount;
int number;
double x1,y1;
double Answer1;
double angle;
system("COLOR 0c");
cout<<" Welcome to TwoSixEight Geeka Scientific Calculator\n";
cout << " Coded by Jenell Joanne James\n\n";
cout << " \n Enter the number of the function you'd like to calculate\n";
do {
cout<<"\t1 ~ Arithmetic Operations \n: ";
cout<<"\t2 ~ Trigonometric Functions \n: ";
cout<<"\t3 ~ Logarithmic Functions \n: ";
cout<<"\t4 ~ Power Functions \n: ";
cout<<"\t5 ~ Exit\n\n:";
choice = getche();
switch(choice)
{
case'1':
{
cout<< " \n\n Welcome to the Arithmetic Operations\n\n";
cout<<" Enter the number of the operator you will like to select\n";
cout<<"\t1 : Addition \n: ";
cout<<"\t2 : subtraction \n: ";
cout<<"\t3 : Multiplication \n: ";
cout<<"\t4 : Division \n: ";
choice1 = getche();
switch(choice1)
{
case'1':
{
cout << "How many numbers are you adding?\n";
cin >> NumbersAmount;
while (loopcount < NumbersAmount){
cout<<"Enter a number: ";
cin>>number;
total = total + number;
loopcount = loopcount+1;
}
cout<<" Total is "<<total<<endl;
break;
}
case'2':
{
cout<<"Enter first number: ";
cin>>x;
cout<<"Enter an other number: ";
cin>>y;
Answer=x-y;
cout<<"The Answer is "<<Answer<<endl;
break;
}
case'3':
{
cout << "\nHow many numbers are you entering?\n";
cin >> NumbersAmount;
while (loopcount < NumbersAmount){
cout<<"Enter your number\n";
cin>>number;
Total1 = Total1 * number;
loopcount = loopcount+1;
}
cout<<" Total is"<<Total1<<endl;
break;
}
case'4':
{
cout<<"Enter first number: ";
cin>>x;
cout<<"Enter an other number: ";
cin>>y;
if(x!=0)
{
Answer=x/y;
cout<<"The Answer is "<<Answer<<endl;
}
break;
}
}// end of inner switch
break;
}// end of case 1 arithmetic operation
case'2':
{
cout<<" Welcome to Trigonometric Functions\n\n";
cout<<"1 ~ Sin function\n:";
cout<<"2 ~ Cos function\n:";
cout<<"3 ~ Tan function\n\n:";
cout<<" Choose your function by typing in the associated number";
choice2=getche();
switch(choice2)
{
case'1': {
cout<<"Enter a angle: ";
cin>>angle;
Answer1=(sin(angle));
cout<<"The answer is "<<Answer1<<endl;
break;
}
case'2':
{
cout<<" Enter a number: ";
cin>>angle;
Answer1=(cos(angle));
cout<<"The answer is "<<Answer1<<endl;
break;
}
case'3':
{
cout<< "Enter a number: ";
cin>>angle;
Answer1=(tan(angle));
cout<<"The answer is "<<Answer1<<endl;
break;
}
}// inner switch
break;
}//inner case 2 trignomatic
case'3':
{
cout<<"\n1 ~ Natural log:";
cout<<"\n2 ~Log with base 10:\n";
choice3=getche();
switch(choice3)
{
case'1':
{
cout<<" Enter a number: ";
cin>>x1;
Answer1=log(x1);
cout<<"The answer is "<<Answer1<<endl;
break;
}
case'2':
{
cout<<"Enter a number: ";
cin>>x1;
Answer1= log10(x1);
cout<<"The answer is "<<Answer1<<endl;
break;
}
}// end of switch
break;
}// end of case 3 logrithmic
case'4':
{
cout<<"\t ~ Press 1 for Power\n";
cout<<"\t ~ Press 2 for Square root:\n";
cout<<"\t ~ Press 3 for Square\n";
cout<<"\t ~ Press 4 for Cube\n\n";
cout<<"\tEnter your choice\n\n:";
choice4=getche();
switch(choice4)
{
case'1':
{
cout<<" Enter a number: ";
cin>>x1;
cout<<" Enter power: ";
cin>>y1; Answer1=pow(x1,y1);
cout<<"The Answer is "<<Answer1<<endl;
break;
}
case'2':
{
cout<<" Enter a number: ";
cin>>x;
Answer1=sqrt(x);
cout<<"The Answer is "<<Answer1<<endl;
break;
}
case'3':
{
cout<<" Enter a number: ";
cin>>x;
Answer1= x*x;
cout<<" The Answer is"<<Answer1<<endl;
break;
}
case'4':
{
cout<<" Enter a number: ";
cin>>x;
Answer1 =x*x*x;
cout<<" The answer is"<<Answer1<<endl;
break;
}
}//end switch
break;
}//end of case power function }//outer switch
}//do
}//
return 0;
}
You don't have the while part of the do while loop :+)
Apart from that, your code is in desperate need of functions. There are so many nested switches; it becomes difficult to follow. I have mentioned this before, hopefully you will take this on board at some stage.
I am not a huge fan of do loops either: Did you know all 3 loops can be converted from one to another? IMO, it is always possible to use a while loop instead of a do loop, maybe at the cost of 1 more variable. Just because a do loop always executes at least once is not a sole reason for using it. A while loop can be written so it always executes at least once.
I am now irate because this is essentially a double post, please don't do this. It may be a different question but it is about the same code. Double posts are essentially a time waster, makes one wonder if they should bother answering at all.