Program shutting down on it's own


#include <iostream>

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.

Any help?
closed account (13bCfSEw)
Hmmm...in your program, you used:

I=U/R;


I understand that Ohm's Law is V = IR which is why you assigned those variables (V, I, R). So the "U" has no place in that program since:

V = I * R

I = V/R

R = V/I

I hope you understand where I'm coming from. :)
Hmmm...in your program, you used:

I=U/R;


I understand that Ohm's Law is V = IR which is why you assigned those variables (V, I, R). So the "U" has no place in that program since:

V = I * R

I = V/R

R = V/I

I hope you understand where I'm coming from. :)



I fixed all that but the same problem still occurs.
Read the thread I linked to.
Registered users can post here. Sign in or register to post.