Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wrote this code please check for errors and suggestions for places to improve.

ID: 671300 • Letter: I

Question

I wrote this code please check for errors and suggestions for places to improve.

//write a program to take depth in kilometers inside the earth as a input data

//compute and display temperature at this depth in celsius and fahrenhiet

#include <iostream>

using namespace std;

void print_introduction(void);

double celsius_at_depth(double depth);

double celsius_to_fahrenheit(double celsius);

void print_conclusion(double c_temp, double f_temp, double depth);

int main{

double celsius, fahrenheit;

print_introduction();

cout << "This program will take a depth inside the earth and compute the temperature"//ask user for depth

<< "at this depth in celsius and fahrenhiet. ";

<< "Enter the depth in kilometers: ";// get input

cin >> depth;

c_temp = celsius_at_depth(depth);

f_temp = celsius_to_fahrenheit(c_temp);

print_conclusion(c_temp, f_temp, depth);//print out the answer

do {

cout << "Do you want to do another one? ";//ask if they want to repeat

cin >> choice;//get input

} while (choice == 'Y' || choice == 'y');//repeat the program

system "pause"

return 0;

}

void print_introduction()

{

cout << endl;

return;

}

double celsius_at_depth(double depth)// formula for celsius at depth

{

return (10*depth+20)

}

double celsius_to_fahrenheit(double celsius)

{

return (1.8*celsius+32)

}

void print_conclusion(double c_temp, double f_temp, double depth)

{

cout << c_temp << " degrees Celsius at a depth of " << depth << endl;

cout << f_temp << " degrees Fahrenheit at a depth of " << depth << endl;

return;

}

Explanation / Answer

Improved program

//write a program to take depth in kilometers inside the earth as a input data

//compute and display temperature at this depth in celsius and fahrenhiet

#include <iostream>

using namespace std;

double celsius_at_depth(double depth);

double celsius_to_fahrenheit(double celsius);

void print_conclusion(double c_temp, double f_temp, double depth);

int main{

double celsius, fahrenheit;

float depth;

cout<< "Enter the depth in kilometers: "<<endl;// get input

cin >> depth;

cout<<endl;

c_temp = celsius_at_depth(depth);/*pass depth into the function which finds the celsius at a given depth and store the celsius in a c_temp variable*/

f_temp = celsius_to_fahrenheit(c_temp); /*pass the celsius value in c_temp variable as an input to the function which computes the farhanhiet and store fahrenheit value in f_temp variable */

print_conclusion(c_temp, f_temp, depth);//print out the answer

char choice;

cout<<enter a choice ; //enter Y or y if you want to continue;

cin>>choice;

if(choice == 'Y' || choice == 'y')

{

main();

}

return 0;

}

double celsius_at_depth(double depth)// formula for celsius at depth

{

return (10*depth+20);

}

double celsius_to_fahrenheit(double celsius)

{

return (1.8*celsius+32);

}

void print_conclusion(double c_temp, double f_temp, double depth)

{

cout << c_temp << " degrees Celsius at a depth of " << depth << endl;

cout << f_temp << " degrees Fahrenheit at a depth of " << depth << endl;

return;

}