LIVE NOW: Shaykh Muhammad al-Yaqoubi talking about his book "Refuting ISIS" at Zaytuna College (ft. Hamza Yusuf)

Hello! Sorry I took two days to get back to you, I had a couple of tests and I was busy studying for those.

Regarding your question about using a while statement in a calculator, take a look at this source code for an integer-arithmetic calculator that I quickly wrote up:

http://cpp.sh/9kan

As you can see per the code, when the program is run it will prompt the user to enter a value for two variables. I have declared/defined these variables as x and y. Another variable is userInput, which is going to be whatever number the user enters into the computer. Then I added a while statement. The while statement works as such.


` > while (expression)

> { > do these statement(s); ` > }


This means that as long as the `(expression) you inserted is true, the computer will execute the statements inside the block { }. If it is false, it will ignore it.

Now, what is the point of the following lines of code:

while (userInput < 1 || userInput >4) { cout << "ERROR: YOU DID NOT ENTER A VALID NUMBER. PLEASE ENTER ANOTHER NUMBER: "; cin >> userInput; ` }

This means that while userInput, or the value the user gives you, is less than 1 OR greater than 4, execute the following :

{ cout << "ERROR: YOU DID NOT ENTER A VALID NUMBER. PLEASE ENTER ANOTHER NUMBER: "; cin >> userInput; }

which pretty much informs the user that he did not choose a valid option (1 - 4), and prompts him to enter another value. This will go on forever until the expression is false, which is only possible if the user enters one of the following numbers: 1, 2, 3, 4.

Now, assuming the user follows the rule and enters a number between 1 and 4, the while statement will not execute. It will not execute because the expression in the parenthesis is FALSE. While statements will only perform the given statements if the initial statement (in this case if they enter a number less than 1 or greater than 4) is true.

Hope this helps. If you have any more questions feel free to PM me or even video Skype for help (you'd have to catch me online).

Good luck with your test.

/r/islam Thread Link - zaytuna.edu