+ 1
why is this not working?
I keep getting compilation error #include <iostream> using namespace std; int main() { int o; int i; int in; float R; cout << "Calculating Shunt Resistance (Rsh)"<<endl ; cin >> o >>endl ; cin >> a >>endl ; cin >> in >>endl ; R = (a /(in -a))×o; cout << "Shunt Resistance= "<< R << endl; return 0; }
10 Respuestas
+ 1
R = (float) (i / (in - i)) * o;
It is returning an int result so you have to cast to float.
Also put a return statement at the end.
+ 1
The int doesn't have a decimal part (the mantissa) so 1/2 would become 0 instead of 0.5. On my compiler by casting to float the mantissa part remains from an equation using int. The compiler was probably warning you that you would lose the mantissa.
0
#include <iostream>
using namespace std;
int main()
{
int o;
int i;
int in;
float R;
cout<<"Calculating Shunt Resistance (Rsh)"<<endl;
cin>>o;
cin>>i;
cin>>in;
R=(i/(in-i))*o;
cout<<"Shunt Resistance= "<<R<<endl;
}
0
still not working
0
Sorry I didn't see your return.
0
Also you have to check (in - i) != 0, or you'll get a division by zero error.
0
till is not work
0
ok guys i got it to work... aparently i needed to declare all variables as a float... can someone explain y
0
cause u r entering float value.
0
no.. all the values that i entered were integers but my result is a float value. i want to know y my inputs need to be floats to get a float result