Pseudocode – Create logic for a program that continually prompts the user for a numeric value until the user enters 0. The application alternately passes the value to a method that squares the number and a method that cubes the number. The program displays the results before restarting the user. Create the two methods that square and cube a number passed to them and then return the calculated value. It’s hard to make a flowchart so I’ll invent a generic coding language
1 write “enter a number
read m
if n = 0 go stop at 2
sq = n*n
cu = cu*n
write (“n=”, n)
write (“n^2 = “, square)
write (“n^3 = “, cu)
return to 1
2 stop i’m having trouble making a flowchart so i’ll invent a generic coding language
1 write “enter a number
read m
if n = 0 go stop at 2
sq = n*n
cu = sq*n
write (“n=”, n)
write (“n^2 = “, square)
write (“n^3 = “, cu)
return to 1
2 stop Here is the pseudo code for you:
Square(x) method:
return x * x; // Square the value passed as input.
Cube(x) method:
return x * x * x ; //Cube the value passed as input.
Main() method:
while(true): // Repeats infinitely.
Ask x.
Read x.
if x == 0:
come back; // Stop execution.
y = Square(x) //Call the Square(x) method.
Print y. //Print the square of a number x.
y = Cube(x) //Call the Cube(x) method.
Print y.
