I need help with grade calculator! thank you!!
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Afternoon Matlab Users,
Hope you're all having the best of days!
This is part of my class homework - I'm trying to make a grade calculator.
where there's a 'Edit Text' user input where 'Number' grade is calculated when pressed the assigned 'Push button'
and another 'Edit Text' where I want display the 'Letter' grade in accordance to the number grade above also via 'Push Button'
Below is my coding:
% --- Executes on button press in enter11.
function enter11_Callback(hObject, eventdata, handles)
if (handles.out19 >70 && <=100)
disp('You achieved a 1st');
elseif (handles.out19 >60 && <=69)
disp('You achieved 2:1');
elseif(handles.out19 >50 && <=59)
disp('You achieved 2:2');
elseif(handles.out19 >40 && <=49)
disp('You achieved 3rd');
elseif(handles.out19 >0 && <=39)
display('You failed');
end
and below is the defined error:
Error while evaluating UIControl Callback.
Relating to this, I also want to display the 'Letter grade' on a Panel.
But i'm struggling!
Help would be appreicated.
1 Commento
Adam Danz
il 23 Mar 2020
Copied here in case the question is edited/deleted as in a previous thead by OP.
----------------------------------------------------------------------------------------------------------
Afternoon Matlab Users,
Hope you're all having the best of days!
This is part of my class homework - I'm trying to make a grade calculator.
where there's a 'Edit Text' user input where 'Number' grade is calculated when pressed the assigned 'Push button'
and another 'Edit Text' where I want display the 'Letter' grade in accordance to the number grade above also via 'Push Button'
Below is my coding:
% --- Executes on button press in enter11.
function enter11_Callback(hObject, eventdata, handles)
if (handles.out19 >70 && <=100)
disp('You achieved a 1st');
elseif (handles.out19 >60 && <=69)
disp('You achieved 2:1');
elseif(handles.out19 >50 && <=59)
disp('You achieved 2:2');
elseif(handles.out19 >40 && <=49)
disp('You achieved 3rd');
elseif(handles.out19 >0 && <=39)
display('You failed');
end
and below is the defined error:
Error while evaluating UIControl Callback.
Relating to this, I also want to display the 'Letter grade' on a Panel.
But i'm struggling!
Help would be appreicated.
Risposta accettata
Geoff Hayes
il 19 Mar 2020
bushra - it isn't clear what handles.out19 is or how it is set, one problem is with
if (handles.out19 >70 && <=100)
and all the other conditions. Note that the condition should be written as
if (handles.out19 >70 && handles.out19 <=100)
and this will be true for all other conditions as well. If handles.out19 is a text control, then you will need to convert that value from a string to a number.
4 Commenti
Geoff Hayes
il 19 Mar 2020
Yes, the display calls will write the output to the command window. I thought that maybe these calls were just for debug purposes. If there is a specifc text control that you want to write to, then you need to do something similar to
set(handles.XYZ, 'String', strMessage);
where XYZ is the handle of the text control that you want to write to, and strMessage is the message that you want to display.
function enter11_Callback(hObject, eventdata, handles)
out19AsNumber = str2double(get(handles.out19, 'String'));
strMessage = '';
if out19AsNumber >70 && out19AsNumber <=100
strMessage = 'You achieved a 1st';
elseif out19AsNumber >60 && out19AsNumber <=69
strMessage = 'You achieved 2:1';
elseif out19AsNumber >50 && out19AsNumber <=59
strMessage = 'You achieved 2:2';
elseif out19AsNumber >40 && out19AsNumber <=49
strMessage = 'You achieved 3rd';
elseif out19AsNumber >0 && out19AsNumber <=39
strMessage = 'You failed';
end
set(handles.XYZ, 'String', strMessage);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!