Question: #include using namespace std; int main() { char ans; int num; cout < < endl < < Do you want to square a number?(y/n) <

#include

using namespace std;

int main()

{

char ans;

int num;

cout << endl << "Do you want to square a number?(y/n)" << endl;

cin >> ans;//1 - START

while ((ans == 'y')||(ans == 'Y')) //2 - TEST

{

cout << "Enter number to be squared: "<< endl;

cin >> num;

cout << "The square of " << num << " is " << num*num << endl;

cout << endl << "Do you want to do another square?(y/n)" << endl;

cin >> ans;

}

return 0;

}

  1. Type in the above program as square.cpp. Add a comment to include your names and date. Compile and run with different values.
  2. Include a line that prints "Good bye!" before the program exits. This should only print once.
  3. What symbol does || stand for in C++?
  4. What happens if you answer "z" when asked if you want to square a number? Why?
  5. Summarize how the above loop works, for example _____ and _____ cause the loop to continue, __________ causes the loop to end.
  6. Modify the program to change the || to &&. What is the result? Why? Change it back when you have answered the question
  7. Comment out (put // at the front of the line) the line that is labeled 1 or START. What happens (is there an error?)? Why? Restore the lines, or un-comment, by removing the // after you have answered the question.
  8. Comment out the line "cin >> ans" near the end of the program. What happens, why? Un-comment the lines after you have answered the question.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!