So i just started C++ yesterday, I had a fair bit of java experience so that be the cause idk, I try to run this code and for some reason the while loop isn't looping, i tried changing the if break statement from ask==false to ask=false, that just ends up with an infinite loop without even taking user input.
Here's the code:
#include <iostream> #include <math.h> using namespace std; int main(){ double raduis; const double pi = 3.14; bool ask; while(true){ cout << "Enter the raduis of the circle:"<< endl; cin >> raduis; double circ = 2*pi*raduis; double area = pi*pow(raduis,2); cout << "The Circumference of the circle is: "<< circ <<endl; cout << "The Area of the circle is: "<< area<<endl; cout <<"Would you like to run again?"<< endl; cin >> ask; if(ask==false){ break; } } } I've tried changing the bool to a char value with "y" or "n" values but to no avail nothing works.
Edit: Okay so I've solved the problem, as per @zdf 's suggestion I entered cin >> boolalpha >> ask; and it works perfectly now.
false. The triple backtics for blocks of code need to be on a new line.std::cin >> std::boolalpha >> ask. You probably enteredtrue. (2) You can useif (ask)....