hello everyone i am new to programming, learned it alone from the internet so i am still weak in C++ and in programming in general. i am working on a small very primitive code just for fun and exersice: a calculator.
i already done the code :
Code:
#include "stdafx.h"
#include <iostream>
#include "conio.h"
#include <iomanip>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
while(1){
cout<<"Enter A to perform an addition\n";
cout<<"Enter B to perform an substraction\n";
cout<<"Enter C to perform a multiplication\n";
cout<<"Enter D to perform a division\n";
cout<<"Enter E to recover the square root\n";
cout<<"Enter F to recover a power\n";
cout<<"Enter G to recover the inverse\n";
cout<<"Enter H to exit the application\n";
char x,z;
cin>>z;
switch(z){
case 'A':{
system("CLS");
cout<<"Enter first value a followed by the second value b to return a+b"<<endl;
int a;
int b;
cin>>a>>b;
cout<<"The sum of the 2 integers is "<<a+b<<endl;
system("Pause");
break;}
case 'B':{
system("CLS");
cout<<"Enter first value a followed by the second value b to return a-b"<<endl;
int a;
int b;
cin>>a>>b;
cout<<"The difference of the 2 integers is "<<a-b<<endl;
system("Pause");
break;}
case 'C':{
system("CLS");
cout<<"Enter first value a followed by the second value b to return a*b"<<endl;
int a;
int b;
cin>>a>>b;
cout<<"The product of the 2 integers is "<<a*b<<endl;
system("Pause");
break;}
case 'D':{
system("CLS");
cout<<"Enter first value a followed by the second value b to return a/b"<<endl;
int a;
int b;
cin>>a>>b;
cout<<"The division of the 2 integers is "<<a/b<<endl;
system("Pause");
break;}
case 'E':{
system("CLS");
cout<<"Enter the value to receive its square-root"<<endl;
double a;
cin>>a;
cout<<"The square-root of the given value is "<<sqrt(a)<<endl;
system("Pause");
break;}
case 'F':{
system("CLS");
cout<<"Enter first value a followed by the second value b to return a^b"<<endl;
double a;
int b;
cin>>a>>b;
cout<<"The difference of the 2 integers is "<<pow(a,b)<<endl;
system("Pause");
break;}
case 'G':{
system("CLS");
cout<<"Enter the value to receive its inverse"<<endl;
double a;
cin>>a;
cout<<"The inverse of the given value is "<<1/a<<endl;
system("Pause");
break;}
case 'H':{
x=z;
break;
}
default:{
cerr<<"Check youre input\n";
system("Pause");
break;}
}
if(x='H'){break;}
}
getch();
return 0;
}
the problem i am having with the switch is the following: when the user inputs the letter H, the while loop break as well as the whole program, that is what is intended. but the thing is that even when you input another letter (A, B or C etc) the program breaks as well when the program shoold return to the beginning of the while loop and re-demand the input...
PS: i intend to make a history and add other things to the application that is why i even bother to break the loop again
thank you in advance for your help..