THERE IS NO PROBLEM IN THIS CODE BECOZ IT WORKS ON OTHER COMPILERS ONLINE BUT IT JUST DOESNT WORK ON VISUAL CODE STUDIO. I dont understand where the problem lies. should i add getc() in the end of the code. it is a C++ program.
#include<iostream>
using namespace std;
int main()
{
int num1, num2; **//codeblock 1**
char p;
cout << "enter 1st numbers:";
cin>>num1;
cout<<"enter a an operand:";
cin>>p;
cout<<"enter 2nd number:";
cin>>num2;
int ans; **//code block 2**
if (p ='+')
{ans=num1+num2;}
else if(p=='-')
{ans=num1-num2;}
else if(p=='/')
{ans=num1/num2;}
else if(p=='*')
{ans=num1*num2;}
else
{
cout<<"invalid operator";
} **//code block 2 end**
cout<<ans;
return 0; **//code block 1 end**
}
Aucun commentaire:
Enregistrer un commentaire