Guest User

Untitled

a guest
Jun 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. [code]
  2. //#include<stdio.h>
  3. #include"stdafx.h"
  4. #include<iostream>
  5. #include<string>
  6. //#include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. double depth, temperatureCelsius, tempCelToFah;
  11. char usersInput;
  12.  
  13. string print_introduction() {
  14. // prints out information to tell the user what this program does.
  15. //cout << "This program calculates the temperature of the earth when given a depth in kilometers" << endl;
  16. return "This program calculates the temperature of the earth when given a depth in kilometersn";
  17. }
  18.  
  19. double celsius_at_depth(double depth) {
  20. // computes and returns the celsius temperature at a depth measured in kilometers.
  21. return temperatureCelsius = 10 * depth + 20;
  22. }
  23.  
  24. double celsius_to_fahrenheit(double celsius) {
  25. // converts a Celsius temperature celsius to Fahrenheit.
  26. return tempCelToFah = 1.8*celsius + 32;
  27. }
  28.  
  29. double print_conclusion(double depth) {
  30. //return
  31. // display the conclusion that what is the temperature in both Celsius and Fahrenheit at depth of the earth
  32. //does all necessary calculations
  33. celsius_at_depth(depth);
  34. celsius_to_fahrenheit(temperatureCelsius);
  35. cout << "The temperature at depth " << depth << " kilometers. In Celsius the temperature is " << temperatureCelsius << "n... in Fahrenheit it is " << tempCelToFah << " degrees.n";
  36. return 0;
  37. //I'm assuming the extra zero in my output comes from this return but I cannot figure out how to get rid of it!!!
  38. }
  39.  
  40. int main()
  41. {
  42. //1. print introduction by calling print_introduction() function
  43. cout << print_introduction() << endl;
  44.  
  45. //2. ask user to enter the depth
  46. cout << "Please enter the depth in kilometers" << endl;
  47.  
  48. //3. get user’s input
  49. cin >> depth;
  50.  
  51. //4. print out the conclusion by calling print_conclusion function
  52. //cout << print_conclusion(depth); //did not work left zero
  53. cout << print_conclusion(depth) << endl;
  54.  
  55. //5. ask user if he/she wants to continue
  56. cout << "Would you like to continue? (y/n)?";
  57.  
  58. //6. get user’s input
  59. cin >> usersInput;
  60.  
  61. //7. repeat step 2 to step 6 if user picks ‘Y’ or ‘y’
  62. if (usersInput == 'Y' || usersInput == 'y')
  63. {
  64. main();
  65. }
  66. else {
  67. //Stop program
  68. return 0;
  69. }
  70. }
  71. [/code]
Add Comment
Please, Sign In to add comment