How do I incorporate the structure array into the while loop? I need help ASAP! TYIA.
Show older comments
You will write a program to ask the user to enter the data in the table given below (prompt the user using input command), and store it in a structure array. (Hint: You will be using a while loop; at the end of the each loop, ask user if they want to enter more data, if yes, add another entry into the structure, else stop). The name of your structure array should be planet (to store information about the planets), and the field names for the structure array are: name, mass, year, velocity.
This is what I have to far. Surprise surprise its not working. Please help.
% This program will take user inputs of planet data and store it into a
% structure array.
n=1;
while n>1
disp('Do you need to enter data?: ');
if n>1 %yes
plant(1).name = input('name');
plant(1).mass = input('mass');
plant(1).year = input('length of year in earth year');
plant(1).velocity = input('mean orbital velocity');
else n<1; %no
end
disp('Do you need to enter data?: ');
if n>1 %yes
plant(2).name = input('name');
plant(2).mass = input('mass');
plant(2).year = input('length of year in earth year');
plant(2).velocity = input('mean orbital velocity');
else n<1; %no
end
disp('Do you need to enter data?: ');
if n>1 %yes
plant(3).name = input('name');
plant(3).mass = input('mass');
plant(3).year = input('length of year in earth year');
plant(3).velocity = input('mean orbital velocity');
else n<1; %no
end
disp('Do you need to enter data?: ');
if n>1 %yes
plant(4).name = input('name');
plant(4).mass = input('mass');
plant(4).year = input('length of year in earth year');
plant(4).velocity = input('mean orbital velocity');
else n<1; %no
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Gravitation, Cosmology & Astrophysics 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!