Students in Computer Science would like to understand the concept of Ohm’s law. You are required to write an application that will allow them to calculate the relation between Voltage, Current and Resistance using the formulas below.
#include <iostream>
using namespace std;
int main()
{
float I, U, R;
cout << "Enter R if you want to find the resistance, I if the current, and U if the voltage: ";
char c;
cin >> c;
switch (c)
{
case 'R':
cout << "Enter the current I: ";
cin >> I;
cout << "Enter the voltage U: ";
cin >> U;
break;
case 'I':
cout << "Enter the voltage U: ";
cin >> U;
cout << "Enter the resistance R: ";
cin >> R;
break;
case 'U':
cout << "Enter the current I: ";
cin >> I;
cout << "Enter the resistance R: ";
cin >> R;
break;
}
switch (c)
{
case 'R':
cout << "Resistance R = "<<U/I<<endl;
break;
case 'I':
cout << "Current I = " << U / R << endl;
break;
case 'U':
cout << "Voltage U = " << R*I << endl;
break;
}
return 0;
}
Comments
Leave a comment