Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double power(double n, int p = 2)
- {
- double total = 1;
- for (int i = 0; i < p; i++)
- {
- total = total * n;
- }
- return total;
- }
- long hms_to_secs(int h, int m, int s)
- {
- int total = 0;
- total = (h * 3600) + (m * 60) + s;
- return total;
- }
- void swap(int& x, int& y) {
- int t = x;
- x = y;
- y = t;
- }
- int main() {
- double n;
- int p;
- cout << "Power Function" << endl;
- cout << "Enter a number " << endl;
- cin >> n;
- cout << "Enter a power " << endl;
- cin >> p;
- cout << n << " to the power of " << p << " is equal to " << power(n, p) << endl;
- int h;
- int m;
- int s;
- char ch;
- cout << "Enter time as HH:MM:SS or enter a negative value for hour to quit " << endl;
- for (int i = 0; i >= 0; i++) {
- cin >> h;
- if (h >= 0)
- {
- cin >> ch >> m >> ch >> s;
- cout << h << ":" << m << ":" << s << " is equal to " << hms_to_secs(h, m, s) << " seconds " << endl;
- cout << "Enter time as HH:MM:SS or enter a negative value for hour to quit" << endl;
- }
- else break;
- }
- int x;
- int y;
- cout << "Enter the first integer " << endl;
- cin >> x;
- cout << "Enter the second integer " << endl;
- cin >> y;
- cout << "The values before swapping are x = " << x << " and " << " y = " << y << endl;
- swap(x, y);
- cout << "The vaues after swapping are x = " << x << " and " << " y = " << y << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement