mardi 22 octobre 2019

Why is this code which is supposed to request an operation then do the necessary calculations not working

include using namespace std;

int main(){ float n1,n2,sum,diff,pro,quot; char f;

cout<<"PLease enter your function(A,S,D,M or X to end the program"<<endl;
cin>>f;


while (f!='A','S','D','M','X'){
  cout<<"Invalid Operation"<<endl;
  cout<<"PLease enter your function(A,S,D,M or X to end the program"<<endl;
  cin>>f;}

    if(f=='X')
  return 0;

if (f=='A','S','D','M'){cout<<"Please enter two numbers";cin>>n1>>n2;

  if (f=='A'){
    sum=n1+n2; 
        cout<<sum;}

    else if (f=='S'){
        if (n1>n2){
          diff=n1-n2;
          cout<<diff;}
          else{
            diff=n2-n1;
              cout<<diff;}
    }
    else if (f=='D'){
        if (n1>n2){
          quot=n1/n2;
          cout<<quot;}
          else{
            quot=n2/n1;
              cout<<quot;}
              }
              else if (f=='M'){
               pro=n1*n2; 
                cout<<pro;}

}

return 0;
}

Its not accepting A,S,M,D

Aucun commentaire:

Enregistrer un commentaire