aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorLibravatar SharafatKarim <sharafat2004@gmail.com>2024-03-10 21:50:38 +0600
committerLibravatar SharafatKarim <sharafat2004@gmail.com>2024-03-10 21:50:38 +0600
commit9bb1850eb74237917c3ff8d3ab8315f3c196ff73 (patch)
tree60df5b0ca119515de1d9a456d570b250baf4b5da /main.cpp
parent0be48808422176133d21147d0dbbeeefdc3d4dac (diff)
parenta2d29e8b76d3969e7c5f4f4509abf92727585a1b (diff)
downloadentropy-calc-9bb1850eb74237917c3ff8d3ab8315f3c196ff73.tar.gz
entropy-calc-9bb1850eb74237917c3ff8d3ab8315f3c196ff73.zip
Merge branch 'main' into vscode
Diffstat (limited to '')
-rw-r--r--main.cpp24
1 files changed, 18 insertions, 6 deletions
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;
}