samedi 20 juin 2015

Decision is not working, if and else if c++

today i learn about if and else if, so an idea came in my mind and i make a program, that takes six numbers and ask for choice, so the adding decision work correctly but other two also work as first decision. Please give me the solution Thanks..

#include<iostream.h>
#include<conio.h>
void main ()
{
int a,a1,a2,a3,a4,a5,adse,sum,sub;
cout<<"\nPlease Enter The First Number : ";
cin>>a;
cout<<"\nPlease Enter The Second Number : ";
cin>>a1;
cout<<"\nPlease Enter The Third Number : ";
cin>>a2;
cout<<"\nPlease Enter The Fourth Number : ";
cin>>a3;
cout<<"\nPlease Enter The Fifth Number : ";
cin>>a4;
cout<<"\nPlease Enter The sixth Number : ";
cin>>a5;
sum=a+a1+a2+a3+a4+a5;
sub=a-a1-a2-a3-a4-a5;
cout<<"\nPlease Select the chioce(1,2,3)";
cout<<"\n1:Adding";
cout<<"\n2:Subtracting";
cout<<"\n3:Exit";
cout<<"\nPlease Enter Your Choice : ";
cin>>adse;
if (adse=1)
{
cout<<"\nThe Addition is : "<<sum;
}
else if(adse=2)
{
cout<<"\nThe Subtraction is : "<<sub;
}
else if(adse=3)
{
cout<<exit(0);
}
else
{
cout<<"\nSorry Wrong Choice, Program is Closing";
}
getch();
}

Aucun commentaire:

Enregistrer un commentaire