+ 1

whats wrong with this code it give zero 0 output !

#include<iostream> #include<stdio.h> #include<conio.h> #include<cstdlib> #include<cmath> using namespace std; float calculator(int a,int b) { int option; switch(option) { case 'p': cout<<a+b; break; case 'i': cout<<a-b; case 'm': cout<<a*b; case 'd': if(0/b) cout<<"solution is unidentified"<<endl; else cout<<a/b; } } int main() { int x,y,p,i,m,d; cout<<"enter two no."<<endl; cin>>x>>y; cout<<"enter p for addition"<<endl; cout<<"enter i for minus"<<endl; cout<<"enter m for multiplication"<<endl; cout<<"enter d for division"<<endl; cin>>p; cin>>i; cin>>m; cin>>d; cout<<calculator(x,y)<<endl; }

22nd Feb 2017, 1:40 PM
Abrar Hussain
Abrar Hussain - avatar
4 Respostas
+ 3
option in calculator method not initialized. so default case is executing. Also you didn't add the default case in switch. Break is missing for I and m cases. please use break statement properly. otherwise it will lead to issue
22nd Feb 2017, 1:47 PM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
+ 1
sir so what i'm use instead of option?
22nd Feb 2017, 2:01 PM
Abrar Hussain
Abrar Hussain - avatar
0
why everybody import the conio header If they aren't going to use it in the program?, besides that, is the most anti-portable header ever.
22nd Feb 2017, 1:51 PM
Fernando
0
u0_a242@j13g:/ $ facebook /system/bin/sh: facebook: not found 127|u0_a242@j13g:/ $ facebok
1st Mar 2017, 10:25 PM
Idoui Badreddine
Idoui Badreddine - avatar