How to make a loop of a calculator that keeps asking until the input is zero/nothing?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Your solution must prompt user to input the option (DR or RD). If the option is DR, then ask for angle in degrees and the program displays the equivalent radians. If the option is RD then ask for angle in radians then the program displays the equivalent degrees. Your program should able to accept both scalar and matrix input. The script should keep running until no number is provided to convert. [The function isempty will be useful here]
i only got this far and there seems to be a problem with my code (when you type a number, it shows 2-4 answer)
choice = menu ('Choose the conversion you want to calculate','DR','RD','Other');
if choice == 1;
fprintf('You have choosen a Degree to Radian conversion');
fprintf('\n');
num = input ('Enter an angle in degrees: ', 's');
result = (num) * pi / 180;
no = str2double(result);
elseif choice == 2;
fprintf('You have choosen a Radian to Degree conversion');
fprintf('\n');
num = input ('Enter a number in Radian: ', 's');
result = (num) * 180 / pi;
no = str2double(result);
else
fprintf('Error mag\n');
end
fprintf('The result of the conversion is %d\n', no);
0 commentaires
Réponse acceptée
Rik
le 24 Nov 2020
You forgot to convert the result to a number, so it is a char array.
%radian = input ('Input a number: ', 's');
%Input a number: 1.2
% this result in:
radian='1.2';
radian=str2double(radian);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!