I need help with grade calculator! thank you!!

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

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.

Accedi per commentare.

 Risposta accettata

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

Miss B
Miss B il 19 Mar 2020
Modificato: Miss B il 19 Mar 2020
Hey,
Thank you for your fast reply!
Much appreciated!
Sorry let me further clarify my answer with this:
function enter7_Callback(hObject, eventdata, handles)
bb = str2double(get(handles.in5,'string'));
cc = str2double(get(handles.in6,'string'));
dd = str2double(get(handles.in7,'string'));
ee = str2double(get(handles.in8,'string'));
ff = str2double(get(handles.in9,'string'));
gg = str2double(get(handles.in10,'string'));
hh = str2double(get(handles.in11,'string'));
ii = str2double(get(handles.in12,'string'));
jj = (bb+cc+dd+ee)/4*0.2 + (ff+gg+hh+ii)/4*0.8
set (handles.out19,'string',num2str(jj));
That is the coding for the above handles.out19
Using the Output (Numerical grade) of handles.out19
I wanted to do display the Letter grade in a text control as well using if, elseif function
so whatever value is displayed on handles.out19 it would at the same display the letter grade in another text control using a button.
Since handles.out19 is a text control, then you would need to convert it to a number. Something like
function enter11_Callback(hObject, eventdata, handles)
out19AsNumber = str2double(get(handles.out19, 'String'));
if out19AsNumber >70 && out19AsNumber <=100
disp('You achieved a 1st');
elseif out19AsNumber >60 && out19AsNumber <=69
disp('You achieved 2:1');
elseif out19AsNumber >50 && out19AsNumber <=59
disp('You achieved 2:2');
elseif out19AsNumber >40 && out19AsNumber <=49
disp('You achieved 3rd');
elseif out19AsNumber >0 && out19AsNumber <=39
display('You failed');
end
Miss B
Miss B il 19 Mar 2020
Modificato: Miss B il 19 Mar 2020
Hi again,
im so sorry for being this annoying :(
The code worked thankfully, but the only problem is...as shown on the above image - i want it to show on the 'Predicted Grade' text control rather than the command window.
Would I put the following command set(handles.in20,'string','');
Thank you.
I hope i can help you the same way you offered to help me.
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);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by