+ 5
Someone help me and correct my first c++ program
#include <iostream> using namespace std; int main() string add='+',sub='-',div='/',mul='*'; char +,-,/,*; {{cin <<"fn"; <<"type"; <<"sn"; if (type=='+') {add=fn+sn; cout <<add;} if(type=='-'){sub=fn-sn; cout <<sub;} if(type=='*') {mul=fn*sn; cout <<mul;} if(type=='/'){ div=fn/sn; cout <<div;} else{cout<<"error";}} return 0
9 Réponses
+ 11
// ffs
#include <iostream>
using namespace std;
int main()
{
int fn;
int sn;
char type;
cin >> fn;
cin >> type;
cin >> sn;
if (type=='+')
{
cout <<fn+sn;
}
else
if(type=='-')
{
cout <<fn-sn;
}
else
if(type=='*')
{
cout <<fn*sn;
}
else
if(type=='/' && sn != 0)
{
cout <<fn/sn;
}
else
{
cout<<"error";
}
return 0;
}
+ 1
#include <iostream>
using namespace std;
int main()
{
float ans;
int fn,sn;
char type;
cin>>fn;
cin>>sn;
cin>>type;
if (type=='+') {ans=fn+sn;
cout <<ans;}
if(type=='-'){ans=fn-sn;
cout <<ans;}
if(type=='*') {ans=fn*sn;
cout <<ans;}
if(type=='/'){
ans=float(fn)/sn;
cout <<ans;}
return 0;
}
+ 1
See this tell me if u get any problem
+ 1
Follow for help, will solve problem whenever will be active
+ 1
run
+ 1
Hatsy u seem mad. xD
0
thanks all it work
0
switch case is easy way. try it