Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // VoltageCalculator.cpp : Defines the entry point for the console application.
- //Beware - move around the headers if constant isnt recognized
- #include "stdafx.h"
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <iostream>
- using namespace std;
- double voltageFormula(double current, double resistance)
- {
- double voltage = current * resistance;
- return voltage;
- }
- double currentFormula(double voltage, double resistance)
- {
- double current = voltage / resistance;
- return current;
- }
- double resistFomula(double voltage, double current)
- {
- double resistance = voltage / current;
- return resistance;
- }
- int main()
- {
- while (true)
- {
- cout << "Choose what you want to solve for: " << endl;
- cout << "1. Voltage" << endl;
- cout << "2. Resistance" << endl;
- cout << "3. Current" << endl;
- int choice;
- cin >> choice;
- if (choice == 1)
- {
- double current, resistance;
- cout << "Enter current: " << endl;
- cin >> current;
- cout << "Enter resistance: " << endl;
- cin >> resistance;
- cout << voltageFormula(current, resistance) << endl;
- }
- else if (choice == 2)
- {
- double voltage, resistance;
- cout << "Enter voltage: " << endl;
- cin >> voltage;
- cout << "Enter resistance: " << endl;
- cin >> resistance;
- cout << currentFormula(voltage, resistance) << endl;
- }
- else if (choice == 3)
- {
- double voltage, resistance;
- cout << "Enter voltage: " << endl;
- cin >> voltage;
- cout << "Enter resistance: " << endl;
- cin >> resistance;
- cout << resistFomula(voltage, resistance) << endl;
- }
- else
- {
- cout << "Something went wrong. Try again." << endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment