Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]
- //#include<stdio.h>
- #include"stdafx.h"
- #include<iostream>
- #include<string>
- //#include <cmath>
- using namespace std;
- double depth, temperatureCelsius, tempCelToFah;
- char usersInput;
- string print_introduction() {
- // prints out information to tell the user what this program does.
- //cout << "This program calculates the temperature of the earth when given a depth in kilometers" << endl;
- return "This program calculates the temperature of the earth when given a depth in kilometersn";
- }
- double celsius_at_depth(double depth) {
- // computes and returns the celsius temperature at a depth measured in kilometers.
- return temperatureCelsius = 10 * depth + 20;
- }
- double celsius_to_fahrenheit(double celsius) {
- // converts a Celsius temperature celsius to Fahrenheit.
- return tempCelToFah = 1.8*celsius + 32;
- }
- double print_conclusion(double depth) {
- //return
- // display the conclusion that what is the temperature in both Celsius and Fahrenheit at depth of the earth
- //does all necessary calculations
- celsius_at_depth(depth);
- celsius_to_fahrenheit(temperatureCelsius);
- cout << "The temperature at depth " << depth << " kilometers. In Celsius the temperature is " << temperatureCelsius << "n... in Fahrenheit it is " << tempCelToFah << " degrees.n";
- return 0;
- //I'm assuming the extra zero in my output comes from this return but I cannot figure out how to get rid of it!!!
- }
- int main()
- {
- //1. print introduction by calling print_introduction() function
- cout << print_introduction() << endl;
- //2. ask user to enter the depth
- cout << "Please enter the depth in kilometers" << endl;
- //3. get user’s input
- cin >> depth;
- //4. print out the conclusion by calling print_conclusion function
- //cout << print_conclusion(depth); //did not work left zero
- cout << print_conclusion(depth) << endl;
- //5. ask user if he/she wants to continue
- cout << "Would you like to continue? (y/n)?";
- //6. get user’s input
- cin >> usersInput;
- //7. repeat step 2 to step 6 if user picks ‘Y’ or ‘y’
- if (usersInput == 'Y' || usersInput == 'y')
- {
- main();
- }
- else {
- //Stop program
- return 0;
- }
- }
- [/code]
Add Comment
Please, Sign In to add comment