Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int wybor;
  5. float r,i,u;
  6. int main()
  7. {
  8. cout<<"Witaj w programie obliczajacym z prawa ohma 3 wartości"<<endl;
  9. cout<<"Nacisnij [1] by obliczyc opor"<<endl;
  10. cout<<"Nacisnij [2] by obliczyc natezenie"<<endl;
  11. cout<<"Nacisnij [3] by obliczyc napiecie"<<endl;
  12. cin>>wybor;
  13. switch (wybor)
  14. {
  15. case 1:
  16. {
  17. cout<<"Wybrales obliczanie oporu"<<endl;
  18. cout<<"Podaj napiecie"<<endl;
  19. cin>>u;
  20. cout<<"Podaj natezenie pradu"<<endl;
  21. cin>>i;
  22. if (i&&u<=0)
  23. {
  24. cout<<"natezenie pradu lub napiecie nie moze byc rowne 0 albo być liczba ujemną"<<endl;
  25. return 0;
  26. }
  27. else
  28. {
  29. r=u/i;
  30. cout<<"Opor to "<<r<<" ohm"<<endl;
  31. }
  32. break;
  33. }
  34. case 2:
  35. {
  36. cout<<"Wybrales obliczanie natezenia"<<endl;
  37. cout<<"Podaj opor"<<endl;
  38. cin>>r;
  39. cout<<"Podaj napiecie"<<endl;
  40. cin>>u;
  41. if (r&&u<=0)
  42. {
  43. cout<<"opor lub napiecie nie moze byc rowne 0 albo być liczba ujemną"<<endl;
  44. return 0;
  45. }
  46. else
  47. {
  48. i=(1/r)*u;
  49. cout<<"Natezenie to "<<i<<" amper"<<endl;
  50. }
  51. break;
  52. }
  53. case 3:
  54. cout<<"Wybrales obliczanie napiecia"<<endl;
  55. cout<<"Podaj opor"<<endl;
  56. cin>>r;
  57. cout<<"Podaj natezenie pradu"<<endl;
  58. cin>>i;
  59. if (r&&i<=0)
  60. {
  61. cout<<"opor lub natezenie pradu nie moze byc rowne 0 albo być liczba ujemną"<<endl;
  62. return 0;
  63. }
  64. else
  65. {
  66. u=r*i;
  67. cout<<"napiecie to "<<u<<" wolt"<<endl;
  68. }
  69. break;
  70.  
  71. defaut:
  72. {
  73. cout<<"Nieprawidlowy wybor"<<endl;
  74. }
  75. break;
  76. }
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement