0% found this document useful (0 votes)
3 views

1

The document contains code for a C++ program that allows users to convert between Fahrenheit and Celsius temperatures. It defines functions to convert temperatures and takes user input to determine which conversion to perform. The main function displays a menu, gets the user's choice, calls the appropriate conversion function, and displays the result.

Uploaded by

Jocel Palmos
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

1

The document contains code for a C++ program that allows users to convert between Fahrenheit and Celsius temperatures. It defines functions to convert temperatures and takes user input to determine which conversion to perform. The main function displays a menu, gets the user's choice, calls the appropriate conversion function, and displays the result.

Uploaded by

Jocel Palmos
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Exercise 1

// Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;

double Fah(double x) {

return (x-32)*5/9;

double Cel(double y) {

return (y*9/5)+32;

int main() {

double a, x, y;

cout << "Press '1' to convert Fahrenheit to Celsius" << endl;

cout << "Press '2' to convert Celcius to Fahrenheit" << endl;

cout << " " << endl;

cout << "Choice: ";

cin >> a;

if (a==1) {

cout << "Enter the Fahrenheit: ";

cin >> x;

double myNum1 = Fah(x);

cout << "In Celsius: " << myNum1 << endl;


}

else {

cout << "Enter the Celcius: ";

cin >> y;

double myNum2 = Cel(y);

cout << "In Fahrenheit: " << myNum2 << endl;

cout << "----------------------------------------------------" << endl;

return main();

}
Exercise 2

// Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;

double Withdraw(double x, double a) {

return x - a;

double Deposit(double x, double b) {

return x + b;

int main() {
double x, y, a, b;

char d;

do {

cout << "Good Day! Welcome to CDM Bank!" << endl;

cout << " " << endl;

cout << "Enter your balance: " << endl;

cin >> x;

cout << " " << endl;

cout << "Select an option: " << endl;

cout << "1. Withdraw Amount" << endl;

cout << "2. Deposit Amount" << endl;

cout << "3. Exit" << endl;

cout << "Option: ";

cin >> y;

cout << "_________________________________________" << endl;

if (y==1) {

cout << "Withdraw Amount" << endl;

cout << "How much money would you like to withdraw from your account?" << endl;

cout << "Amount: ";

cin >> a;

double myNum1 = Withdraw(x,a);

cout << "Your new balance is: " << myNum1 << endl;

cout << " " << endl;

}
else if (y==2) {

cout << "Deposit Amount" << endl;

cout << "How much money would you like to deposit from your account?" << endl;

cout << "Amount: ";

cin >> b;

double myNum2 = Deposit(x,b);

cout << "Your new balance is: " << myNum2 << endl;

cout << " " << endl;

else {

cout << "Thank you for using the system!" << endl;

cout << "Would you like to do another transaction ('Y' if Yes/ 'N' if No)" << endl;

cout << "Choice: ";

cin >> d;

cout << " " << endl;

while (d == 'Y' || d == 'y');

cout << "Thank you for using this system!" << endl;

return 0;

You might also like