Hey all im a beginner in c++.
Ive written this programme and ive tried to make a calculator using switch statement but its not working like it should.I would be very thankful if u point out whats wrong with it.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float x,y;
int choice;
cout<<"Enter 1,2,3,4 for +,-,x,/ respectively"<<endl;
cin>>choice;
cout<<"Enter the numbers"<<endl;
cin>>x>>y;
switch(choice)
case1 :
cout<<x<<" + "<<y<<" = "<<x+y;
cout<<endl;
case2 :
cout<<x<<" - "<<y<<" = "<<x-y;
cout<<endl;
case3 :
cout<<x<<" x "<<y<<" = "<<x*y;
cout<<endl;
case4 :
if (y==0)
cout<<"division not possible"<<endl;
else
cout<<x<<" / "<<y<<" = "<<x/y;
cout<<endl;
getch();
}
Output is
Enter 1,2,3,4 for +,-,x,/ respectively
1
Enter the numbers
25
20
25 - 20 = 5
25 x 20 = 500
25 / 20 = 1.25
so the problem is that when i enter 1 it is supposed to add 20 and 25 but its not doing that.where is the problem?