How to use while true loop for this qustion?

조회 수: 20 (최근 30일)
mahmoud Tarek
mahmoud Tarek 2020년 9월 19일
댓글: Walter Roberson 2020년 9월 24일
The Fahrenheit temperature is converted to Celsius temperature by the following formula , write a script file to accept temperature in Fahrenheit and calculate its Celsius equivalent for 5 times using DO WHILE loop.
While writing the Program please consider the Following:
  1. The program must ask the user to input the temperature in Fahrenheit.
  2. The program must display the temperature in Celsius.
  댓글 수: 7
mahmoud Tarek
mahmoud Tarek 2020년 9월 23일
편집: mahmoud Tarek 2020년 9월 24일
Sorry to ask again. is thes anser true?
x=1;
while true
F = input('inter the degree in Fahrenheit: ');
C = ( F - 32 )*5/9;
fprintf("the degree in Celsius is: %f°F \n",C)
if x == 5
break
end
x = x + 1;
end
Walter Roberson
Walter Roberson 2020년 9월 24일
It's okay.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 9월 19일
assign initial conditions
while true
do a calculation
if condition is satisfied
break;
end
end
here, "condition is satisfied" needs to be expressed the opposite way than you would use for a "do while". For example in C
do {
x = rand();
} while x > 0.1;
would become
while true
x = rand() ;
if x <= 0.1; break; end
end
Notice the C condition of x > 0.1 becomes the condition x <= 0.1

추가 답변 (1개)

stozaki
stozaki 2020년 9월 19일
편집: stozaki 2020년 9월 19일
Hello
Here is an example of calculation
% Define the value of F used in the calculation as a "vector".
F = [70 80 75 84 92];
% Calculate the average value of F using the mean function.
AveC = mean(5/9*(F - 32))
AveC =
26.7778
documentation for mean function
stozaki

카테고리

Help CenterFile Exchange에서 Testing Frameworks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by