The Way to Programming
The Way to Programming
How do I keep looping so that if the user keeps pressing a negative number it keeps displaying the message “error”?
g=9.81 V0=input ('Enter initial velocity of projectile (m/s):') if V0<0 disp ('Error. Velocty must be greater than 0'); V0=input ('Enter initial velocity of projectile (m/s):') else x=input ('Enter target location in X direction (>0m):') theta=(asin(x*g/V0^2))/2 end
If i keep inputting a negative answer it keeps repeating which i want
but if i run the program from the beginning and input a vale >0 for V0 it jsut falls through and gives an answer for theta without asking for the x value
g=9.81 V0=0 V0=input ('Enter initial velocity of projectile (m/s):') while (V0<0) disp ('Error. Velocty must be greater than 0'); V0=input ('Enter initial velocity of projectile (m/s):') if (V0>0) x=input ('Enter target location in X direction (>0m):') theta=(asin(x*g/V0^2))/2; end end theta
Sign in to your account