I'm required to write a program what will accept positive numbers, and calculate both the average of them and the geometric mean(nth root of (x1*x2*x3…*xn). While loops are to be used to get the input numbers, and terminate the inputs that are negative. While loops in general confuse me so can you please tell me what i did wrong.
ttotal=0;
total=0;
cnt=0;
x=1;
y=1;
while x>=0
x=input('Please enter a positive number:'); cnt=cnt+1; total=(total+x)/cnt; if x<0 break; endwhile y>=0 y=input('Please enter a positive number:'); cnt=cnt+1; ttotal=(ttotal*y)^(cnt/2); if y<0 break; end fprintf('The geometric mean is %g',ttotal) fprintf('The average of the inputed numbers is %g',total)endendfprint('Program-Terminated')
Best Answer