C++ BMI Project

#include <iostream>

int main() {
  double height, weight, bmi;
  // Ask user for their height
  std::cout << "Type in your height (m): ";
  std::cin >> height;
  // Now ask the user for their weight and calculate BMI
  std::cout<< "Type in your weight (kg):";
  std::cin >> weight;
  bmi = weight/(height)^2;
  std::cout << "Your BMI is "<< bmi << "\n";
  return 0;

Why isn’t my code asking for the weight even though I have my code written exactly like the hint?

Could you share the project url? So i can run the code (can’t find the project)

That doesn’t compile, which is something you need to look at before you consider how something behaves (you can’t even run it otherwise)
Same with warnings, always compile with -Wall to turn on warnings and if there are any then there’s no point considering behaviour of the program, something wrong has already been found.

And no it’s not exactly like the … (that’s not a hint that’s a complete program), so, you’ll need to modify your definition of the word exact to mean byte-for-byte-exactly-the-same-without-a-single-difference, indistinguishable. Exact doesn’t mean “looks the same”!

1 Like


When I try to compile code similar to yours I get the following error:

Not every operator does the same thing in every language. ^ isn’t what you think it is in C++.