What to do when your code is stuck on one switch statement

Hello, I’m just new to programming in c++, while coding stuff in my program i run to a error that always the Radius is showing up no the other equation, no matter how many tiles i edit the code there’s always a problem

Here’s my code btw:

#include
#include
using namespace std;

string Codema (int ali){
string codeent;

switch (ali){
	case 1:
		double ac,r;
		cout<<"============================="<<endl;
		cout<<"Enter Radius:\t";
		cin>>r;
		cout<<"Area = Pi x"<<r<<"^2"<<endl;
		ac=3.1416*r*r;
		cout<<"Area = "<<ac<<endl;
		break;
	case 2:
		double b,h,at;
		cout<<"============================="<<endl;
		 cout<<"Enter Base:\t";
		 cin>>b;
		 cout<<"Enter Hieght:\t";
		 cin>>h;
		 cout<<"Area = "<<b<<" x "<<h<<endl;
		 at=b*h;
		 cout<<"Area = "<<at<<endl;			
		break;
	case 3:
		double l,w,ar;
		cout<<"============================="<<endl;
		 cout<<"Enter Lenght:\t";
		 cin>>l;
		 cout<<"Enter Widght:\t";
		 cin>>w;
		 cout<<"Area = "<<l<<" x "<<w<<endl;
		 ar=l*w;
		 cout<<"Area = "<<ar<<endl;	 			
		break;
	case 4:
		double as, s;
		cout<<"============================="<<endl;
		 cout<<"Enter Side:\t";
		 cin>>s;
		 cout<<"Area = "<<s<<" ^2 "<<endl;
		 as=s*s;
		 cout<<"Area = "<<as<<endl;				 
		break;
	default:
		cout<<"error 404";
		break;
	
 }
return codeent;

}

void welcome(){
cout<<“CSS=Area Program…”<<endl;
cout<<“\n===================================================================”<<endl;
return;
}

void choice(){
cout<<“Choose the Area you like to compute…”<<endl;
cout<<“Available Formulas”<<endl;
cout<<“-Circle \t or c “<<endl;
cout<<”-Triagle \t or t “<<endl;
cout<<”-Rectangle \t or r “<<endl;
cout<<”-Square \t or s”<<endl;
}

void Leed(int ali,int cole){

}

int main(){
welcome();
int ali,cole={
1,2,3,4,5
};
int lol =0;
int loli =57;
bool log=false;
while(!log){
if(lol<loli){
choice();
string a;
cout<<“Enter the Formula:\t”;
cin>>a;
if(a==“circle”||“Circle”||“c”||“C”){
ali=cole[0];
Codema(ali);

				}else if(a=="triangle"||"Triangle"||"t"||"T"){
					ali=cole[1];
					Codema(ali);
				}else if(a=="rectagle"||"Rectangle"||"r"||"R"){
					ali=cole[2];
					Codema(ali);
					
				}else if(a=="square"||"Square"||"s"||"S"){
					ali=cole[3];
					Codema(ali);
					
				}else{
					ali=cole[4];
					Codema(ali);
				}
			cout<<"============================="<<endl;
			lol++;
		}else{
			log=true;		
		}
	}



return 0;

}

Idk why cuz my code is complete but there’s always a problem in the switch statement,
I hope someone can help me fix this :sweat_smile:

That may not work right because the strings can act like true in the if-statement condition.

You could do

if(a=="circle" || a =="Circle" || a=="c" || a=="C"){

to make it work the way you expect.

1 Like