using namespace std;
int main() {
int I,V,R,a;
cout<<"Select wether you would like to calculate R, I or V."<<endl;
cout<<" "<<endl;
cout<<"To select the resistance, press 1."<<endl;
cout<<"To select the electric current, press 2."<<endl;
cout<<"To select the voltage, press 3."<<endl;
cin>>a;
switch(a){
case 1: cout<<"Type in the values that are needed to calculate R."<<endl;
cout<<" "<<endl;
cout<<"V=";
cin>>V;
cout<<" "<<endl;
cout<<"I=";
cin>>I;
R=U/I;
cout<<"R="<<R<<endl;
break;
case 2: cout<<"Type in the values that are needed to calculate I."<<endl;
cout<<" "<<endl;
cout<<"V=";
cin>>V;
cout<<" "<<endl;
cout<<"R=";
cin>>R;
I=U/R;
cout<<"I="<<I<<endl;
break;
case 3: cout<<"Type in the values that are needed to calculate V."<<endl;
cout<<" "<<endl;
cout<<"I=";
cin>>I;
cout<<" "<<endl;
cout<<"R=";
cin>>R;
U=I*R;
cout<<"V="<<V<<endl;
break;
default:
cout<<"You haven't entered any of the available values."<<endl;}
return 0;
}
This program is representing Ohm's law.
When I launch the console and after typing the 2 values needed to calculate I, R or V, the console closes immediately without showing the result.