Factorial Loop Body Error

Procedure

Real Lab Procedure

  1. Creating a variable "num" to hold the number entered by the user. 
  2. Variable "fact" is used to hold the factorial of the given number, which is initialized to value 1. 
  3. Loop variable "i" is initialized to the value 1. 
  4. "while" loop is used to calculate the factorial of the given number. 
  5. "while" loop will execute till "i" is less than or equal to  the given input number. 
  6.  Inside "while" loop, two important operations are carried out:  

           a) "fact= fact+ i" (produce incorrect result because of using addition instead of multiplication)

           b) "i=i+1" 

7. Print the factorial of the given number when exiting from the "while" loop. 

         

Simulator Procedure

  • Enter the input values. 
  • Click on the Submit button. 
  • Select the variables from the dropdown list.
  • Click on the Finish button or Start button to view the State diagram.
  • If you have clicked on the Start button, then use the Next and Previous buttons to view the State diagram.
  • Click on the Reset button when the State diagram is completed.