Hi I am trying to make Height Energy Calculator but after the if statement It is just close the program.
This is the Code:
#include <iostream> #include <string> #include <vector> int main() { bool Ph = true; std::cout << "Height True Or False: n"; std::cin >> Ph; double M = 0; double G = 0; double H = 0; if (Ph == true) { std::cout << "Mass:n"; std::cin >> M; std::cout << "Gravity:n"; std::cin >> G; std::cout << "Height:n"; std::cin >> H; } } double PhyH(double M, double G, double H) { return (M * G) * H; }
Thanks for the helpers.
Answer
You have to call your function if you want to use it (inside your main, after the if statement). You are only defining it.
std::cout << PhyH(M, G, H);
Also you have to at least declare it before your main (same way you defined it but without the body)
For problems like this there really is a lot of places to read up on them; you might wanna check this out or you’re gonna have a lot of questions.