Today I learned about if and else if. So an idea came in my mind and I make a program, that takes six numbers and ask for a choice, so the adding decision work correctly, but other two also work as first decision. What is the solution?
#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, or 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();
}