From c237e0c92ecee53ed7352b83c69da9aabafcd26b Mon Sep 17 00:00:00 2001 From: SR Tamim Date: Sat, 9 Mar 2024 00:29:25 +0600 Subject: calculation of total heat fixed --- main.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 6b6fa8e..9b78f4f 100644 --- a/main.cpp +++ b/main.cpp @@ -20,13 +20,25 @@ int main() double mass, fromTemp, toTemp; cout << "Enter the mass of the element (in Kg): "; - cin >> mass; + cin >> mass; + if (mass <= 0) + { + cout << "Mass must be a positive value" << endl; + return 0; + } cout << "Enter the initial temperature of the element (in K): "; cin >> fromTemp; cout << "Enter the final temperature of the element (in K): "; - cin >> toTemp; - - cout << "The total heat needed is: " << elements[choice - 1]->totalHeatNeeded(mass, fromTemp, toTemp) << " J" << endl; - - cout << "The total entropy change is: " << elements[choice - 1]->totalEntropyChange(mass, fromTemp, toTemp) << " J/K" << endl; + cin >> toTemp; + if (fromTemp > toTemp) + { + cout << "Initial temperature can not be greater than final temperature" << endl; + return 0; + } + + double totalHeat = elements[choice - 1]->totalHeatNeeded(mass, fromTemp, toTemp); + double totalEntropy = elements[choice - 1]->totalEntropyChange(mass, fromTemp, toTemp); + cout << "The total heat needed is: " << totalHeat << " J" << endl; + cout << "The total entropy change is: " << totalEntropy << " J/K" << endl; + return 0; } -- cgit v1.2.3