Science: Calculating Energy

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

For the inputs, I believe you run the code and use the file name as an extra parameter.

Question

<— Return Home

210.cpp

#include <iostream>
// #include <math.h> //round, floor, ceil, trunc
using namespace std;

int main(){
    double water_in_kilograms;
    double initialTemp;
    double finalTemp;
    double energy_needed;

    std::cout << "Enter the amount of water in kilograms: \n";
    std::cin >> water_in_kilograms;
    std::cout << "Enter the initial temperature: \n";
    std::cin >> initialTemp;
    std::cout << "Enter the final temperature: \n";
    std::cin >> finalTemp;

    energy_needed = water_in_kilograms * (finalTemp - initialTemp) * 4184;
    // energy_needed = round(energy_needed * 10);

    std::cout << "The energy needed is " << energy_needed;
}

<— Return Home

Inputs (210input.txt)

55.5
3.5
10.5

<— Return Home