How do i make this script produce a tidy output screen? I have come up with the script but cannot tidy it up.
2 views (last 30 days)
Show older comments
Output screen:
Please enter a positive number : 1
Please enter a positive number : 2
Please enter a positive number : 4
Please enter a positive number : 5
1: x = 1.000 , product = 1.000
2: x = 2.000 , product = 2.000
3. x = 4.000 , product = 8.000
etc
My script:
clear
clc
x=input('Enter a positive number : \n');
product = x*1;
while product <=500
x = input('Enter a positive integer : ');
product = product*x;
fprintf('x = %4.3f , product = %4.3f\n' ,x, product);
end
fprintf('x = %4.3f, product = %4.3f:', x, product);
1 Comment
Adam
on 25 Nov 2015
I don't understand what you are aiming for. Are you trying to format it better or what?
I get an output something like this.
Enter a positive number :
2
Enter a positive integer : 3
x = 3.000 , product = 6.000
Enter a positive integer : 6
x = 6.000 , product = 36.000
Enter a positive integer : 12
x = 12.000 , product = 432.000
Enter a positive integer : 2
x = 2.000 , product = 864.000
x = 2.000, product = 864.000
Obviously if you remove some fprintf statements the output screen will be tidier, but I assume you want to output everything that you currently do.
Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!