I can't figure out how to ask for the number of resistors that has to be an integer up to 10 and then use a loop to enter R1, R2, ... Rn

1 view (last 30 days)
My homework says to ask if the combination is in series or parallel and I believe I have that done but then I need it to ask for the number of resistors (integer up to 10) and also use a loop to enter R1, R2, ...Rn
So far I have
C=input('Input if the combination is in series or parallel: ','series','parallel');
n=input('Enter the number or resistors');
>> while n=int32(n)
n=input('Enter the number of resistors: ');
fprintf('Enter an integer up to 10')
end
I'm not sure if this is even right for n and can't figure out how to ask the user to input value for R1, R2...
  4 Comments
Rik
Rik on 17 Feb 2020
Read the linked page. Your professor not helping you doesn't make your question urgent. Just remove the word urgent from your question, because that only causes people to ignore the rest of the question.

Sign in to comment.

Answers (1)

Joel Bay
Joel Bay on 17 Feb 2020
Just need to prompt the user for each resistor, changing the prompt via format specifiers.
for i = 1:n
msg = sprintf('Enter Resistance of Resistor R%d: ', i);
R(i) = input(msg);
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!