Programming help

#include<iostream>
#include<cmath>
using namespace std;
int main(){
float a,b,z,m,n,p,r,s;
int x,y,q;
char c;
cout<<"Choose a claculator by typing 1 or 2 or 3 "<<endl;
cout<<"1. Standard"<<endl;
cout<<"2. Scientific"<<endl;
cout<<"3. Trigonometric"<<endl;
cin>>x;
if(x==1){
cout<<"Please enter your calculation in the following format a+b"<<endl;
cin>>a>>c>>b;
switch(c){
case('+'):
cout<<"The results is "<<a+b<<endl;
break;
case ('-'):
cout<<"The result is "<<a-b<<endl;
case('*'):
cout<<"The results is "<<a*b<<endl;
break;
case('/'):
cout<<"The results is "<<a/b<<endl;
break;
}
}
if(x==2){
cout<<"Choose a operation by typing 1 or 2 or 3 "<<endl;
cout<<"1.log"<<endl;
cout<<"2.sqrt"<<endl;
cout<<"3.power"<<endl;
cin>>y;
if(y==1){

cout<<"Please enter any positive number "<<endl;
cin>>z;
cout<<"The results is"<<log(z)<<endl; };
if(y==2){
cout<<"Please enter any positive number "<<endl;
cin>>m;
cout<<"The resuots is "<<sqrt(m)<<endl;};
if(y==3){
cout<<"please 1st enter number and than power "<<endl;
cin>>n>>p;
cout<<"The results is "<<pow(n,p)<<endl;
};
};
if(x==3){
cout<<"choose aoperation by typing 1 or 2 or 3 "<<endl;
cout<<"1) sine"<<endl;
cout<<"2) cosine"<<endl;
cout<<"3) tan"<<endl;
cin>>q;
cout<<"please enter your angle in degree"<<endl;
cin>>r;
s=(r*3.1416)/180 ;
if(q==1)
cout<<"The results is "<<sin(s)<<endl;
else if(q==2)
cout<<"The results is "<<cos(s)<<endl;
else if(q==3)
cout<<cout<<"The results is "<<tan(s)<<endl;
};
system("pause");
return 0;
}

This is what i have so far but i dont know how to Input validation. Each input needs to be validated to check if it was acceptable. if not, you give the user another chance to try again and The program menu should The program should end only when the user chooses the Quit option







Use code tags
Here is an example of how to deal with selecting menu items, but app loops indefinitely @ 19 if input is non-numeric.

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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

	vector <string> Menu {"Standard", "Scientific", "Trigonometric","Quit"};
	
int main (void) {
	unsigned selection;
	
	cout << "Select menu item by number\n\n";
	selection = 1;
	for (auto item : Menu)
		cout << " [" << selection++ << "] " << item << endl;
	
	do {
		cout << " Choose [ 1 - " << Menu.size () << " ] --> ";
		cin >> selection;
		
		switch ( selection ) {
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				selection = 0;
				break;
			default:
				selection = 100;	  // So while loop won't bail if "0".
				cout << "Invalid ";
		}
		
	} while ( selection );
	
	return 0;
}
Topic archived. No new replies allowed.