Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int wybor;
- float r,i,u;
- int main()
- {
- cout<<"Witaj w programie obliczajacym z prawa ohma 3 wartości"<<endl;
- cout<<"Nacisnij [1] by obliczyc opor"<<endl;
- cout<<"Nacisnij [2] by obliczyc natezenie"<<endl;
- cout<<"Nacisnij [3] by obliczyc napiecie"<<endl;
- cin>>wybor;
- switch (wybor)
- {
- case 1:
- {
- cout<<"Wybrales obliczanie oporu"<<endl;
- cout<<"Podaj napiecie"<<endl;
- cin>>u;
- cout<<"Podaj natezenie pradu"<<endl;
- cin>>i;
- if (i&&u<=0)
- {
- cout<<"natezenie pradu lub napiecie nie moze byc rowne 0 albo być liczba ujemną"<<endl;
- return 0;
- }
- else
- {
- r=u/i;
- cout<<"Opor to "<<r<<" ohm"<<endl;
- }
- break;
- }
- case 2:
- {
- cout<<"Wybrales obliczanie natezenia"<<endl;
- cout<<"Podaj opor"<<endl;
- cin>>r;
- cout<<"Podaj napiecie"<<endl;
- cin>>u;
- if (r&&u<=0)
- {
- cout<<"opor lub napiecie nie moze byc rowne 0 albo być liczba ujemną"<<endl;
- return 0;
- }
- else
- {
- i=(1/r)*u;
- cout<<"Natezenie to "<<i<<" amper"<<endl;
- }
- break;
- }
- case 3:
- cout<<"Wybrales obliczanie napiecia"<<endl;
- cout<<"Podaj opor"<<endl;
- cin>>r;
- cout<<"Podaj natezenie pradu"<<endl;
- cin>>i;
- if (r&&i<=0)
- {
- cout<<"opor lub natezenie pradu nie moze byc rowne 0 albo być liczba ujemną"<<endl;
- return 0;
- }
- else
- {
- u=r*i;
- cout<<"napiecie to "<<u<<" wolt"<<endl;
- }
- break;
- defaut:
- {
- cout<<"Nieprawidlowy wybor"<<endl;
- }
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement