Hi guys, I'm trying to write a program that takes the Voltage, and Current as input, and then generates the Resistance. According to my task both inputs HAS to be integers, the output has to display 3 decimal places, but for some reason the decimals displays ".000" no matter what I do, I want it to display "4.234" instead of "4.000" for example.
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int Voltage;
int Current;
double Resistance;
cout << "Enter the Voltage: ";
cin >> Voltage;
cout << "Enter the Current: ";
cin >> Current;
Resistance = (Voltage/Current);
cout << "The resistance is " << fixed << setprecision(3) << Resistance << " ohm" << endl;
return 0;
If the answer should be for example 7.324, it displays the answer as 7.000, how can I fix this?