Answer to Question #159140 in C++ for Kefilwe

Question #159140

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.


1
Expert's answer
2021-01-28T04:28:18-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog