0

I need to make a 'Calculator' that works out and average for 3 different marks.

procedure TForm1.btnAddClick(Sender: TObject);
var
    sName                          : string;
    iprac, itheory, iproject       : integer;
begin
 sName := edtStudentName.text;
 iprac := sedPrac.value;
 iTheory := sedTheory.Value;
 iProject := sedProject.Value;
  lblOutput.caption := sName + ' You got ' + IntToStr (iPrac + iTheory + iProject) / 3;

end;
end.

Thats the code so far, but I get an error:

[Error] ComputerStudyMarks_u.pas(46): Incompatible types: 'String' and 'Integer'

Please be patient with me! I am a hardcore noob but this is for school. Maybe someone can help me with this program. I am busy using the book "Enjoy Delphi" and the code I am copying from the book itself is giving me an error. Any help would be much appreciated! P.S I cant add a picture of the form because I dont have enough reputation :(

1 Answer 1

1
iprac := sedPrac.value;

It's not clear what sedPrac is. And therefore what the Value property it. If Value is a string then you cannot assign a string to an integer. Your would need to convert to integer first, like this:

iprac := StrToInt(sedPrac.value);

Likewise for iTheory and iProject.

Of course, it may be that Value is already an integer, in which case your code is fine. My best guess is that these variables refer to TSpinEdit controls, and that Value is an integer, and so all is well. But that is just a guess.


IntToStr (iPrac + iTheory + iProject) / 3

Now, IntToStr is a function that returns a string. And there is no / operator defined for strings. Presumably you meant to write:

IntToStr((iPrac + iTheory + iProject) div 3)

Note that you have to use div since the value is an integer and / is floating point division.


Some final pieces of advice.

  • When presenting code, present all the information. You omitted to present some types here and so we don't know what sedPrac is.
  • When you present an error message, make sure that we can marry up the line number in the message with the code that you present. In your question, we don't know which line is line 46.
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you!Sorry for not adding enough information. btw, sedPrac refers to s SpinEdit. Your answer is much appreciated. Also, the theory and practical marks are out of 40, and the project mark is out of 20, how would I get the value in % for all three marks?
40+40+20=100. So you just need to add the raw results. In other words, iPrac + iTheory + iProject gives you the overall percentage mark. You might want to add some validity checking to make sure that nobody enters an out of range score.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.