Guest User

Untitled

a guest
Nov 14th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // VoltageCalculator.cpp : Defines the entry point for the console application.
  2. //Beware - move around the headers if constant isnt recognized
  3.  
  4.  
  5. #include "stdafx.h"
  6. #define _USE_MATH_DEFINES
  7. #include <cmath>
  8. #include <iostream>
  9. using namespace std;
  10.  
  11.  
  12. double voltageFormula(double current, double resistance)
  13. {
  14. double voltage = current * resistance;
  15. return voltage;
  16. }
  17. double currentFormula(double voltage, double resistance)
  18. {
  19. double current = voltage / resistance;
  20. return current;
  21. }
  22. double resistFomula(double voltage, double current)
  23. {
  24. double resistance = voltage / current;
  25. return resistance;
  26. }
  27. int main()
  28. {
  29.  
  30. while (true)
  31. {
  32. cout << "Choose what you want to solve for: " << endl;
  33. cout << "1. Voltage" << endl;
  34. cout << "2. Resistance" << endl;
  35. cout << "3. Current" << endl;
  36. int choice;
  37. cin >> choice;
  38. if (choice == 1)
  39. {
  40. double current, resistance;
  41. cout << "Enter current: " << endl;
  42. cin >> current;
  43. cout << "Enter resistance: " << endl;
  44. cin >> resistance;
  45. cout << voltageFormula(current, resistance) << endl;
  46. }
  47. else if (choice == 2)
  48. {
  49. double voltage, resistance;
  50. cout << "Enter voltage: " << endl;
  51. cin >> voltage;
  52. cout << "Enter resistance: " << endl;
  53. cin >> resistance;
  54. cout << currentFormula(voltage, resistance) << endl;
  55. }
  56. else if (choice == 3)
  57. {
  58. double voltage, resistance;
  59. cout << "Enter voltage: " << endl;
  60. cin >> voltage;
  61. cout << "Enter resistance: " << endl;
  62. cin >> resistance;
  63. cout << resistFomula(voltage, resistance) << endl;
  64. }
  65. else
  66. {
  67. cout << "Something went wrong. Try again." << endl;
  68. }
  69. }
  70. return 0;
  71. }
Add Comment
Please, Sign In to add comment