![]() |
can anyone program in turbo pascal - need help!!!
my program will not work and i don't no y and its stressing me out so much
it says i need a semi-colon on the line until menu ='4' but it still says that wen i put one on program task2a; uses crt; var password, userpass, newpass1, newpass2 : string[10]; flag, count, n, add, times, total : integer; answer, menu : char; begin clrscr; password := 'computer'; flag := 0; repeat clrscr; writeln('please enter the password'); readln(userpass); if userpass = password then begin writeln('the password you entered is correct'); readln; clrscr; repeat clrscr; writeln('1 - change password'); writeln('2 - add several numbers'); writeln('3 - multiply several numbers'); writeln('4 - exit'); readln(menu); case menu of '1' : begin writeln('do you wish to change ur password? y/n'); readln(answer); if (answer = 'y') or (answer = 'Y') then begin repeat clrscr; writeln('please enter your new password'); readln(newpass1); writeln('please enter your new password'); readln(newpass2); clrscr; if newpass1 = newpass2 then begin writeln(' your new password has been set'); readln; end else begin writeln('the two passwords do not match'); writeln; writeln('please try again'); readln; end; until newpass1 = newpass2 end else begin writeln('your password has remained the same'); readln; end; end; '2' : begin writeln('how many numbers do you wish to add?'); readln(n); for count := 1 to n do begin clrscr; writeln('please enter a number'); readln(add); total := total + add; writeln('the total so far is ',total); end; writeln('the total is ',total); end; '3' : begin writeln('how many numbers do you wish to multiply?'); readln(n); for count := 1 to n do begin clrscr; writeln('please enter a number'); readln(times); total := total * times; writeln('the total so far is ',total); end; writeln('the total is ',total); end; '4' : begin writeln(' you have chosen to exit'); readln; end; else begin writeln('this is not a valid option'); readln; end; until menu = '4' end; else begin flag := flag + 1; writeln('the password you entered is incorrect'); writeln('you have used ', flag,' out of 3 tries'); readln; end; until (flag = 3) or (userpass = password); if flag = 3 then begin writeln('you have used up all of your attempts'); writeln; end; writeln('the program will now end'); readln; end. writeln('you have used up all of your attempts'); writeln; end; writeln('the program will now end'); readln; end. |
Sorry been ages since I used pascal, but if I remember right a ; before end is optional, so chances are its being fussy and the problem isn't where it thinks it is
best to add the ; to the end of every line anyway just to rule out a missing one higher up that should be optional but isn't (also good practice for if you move onto c or java based languages) obviously don't add to the end of lines that aren't supposed to have them or you'll possibly find unexpected results Also make sure your begin and ends all match up another thing worth trying is to enclose the condition in () this just makes sure the compiler sees what you want it to see so "until (menu = '4');" Sorry can't actually see anything obvious, it all looks fine to me |
Im not used to this type of programming as I use visual studio an C++, but
'4' : begin writeln(' you have chosen to exit'); readln; You have not named what you want to call the readin, so it has nowhere to store it. could that be the missing problem? |
bitter_angel: you put readln; when you want the user to press enter before going on to the next line.
pictsie: im learning it in college and have to for the exams. ill try utting in the () thank you thanks chelsie |
cant help then, its completly differnt from visual basics where you have to call a function.
|
pictsie : thanks for trying but it didnt work
|
I don't know pascal so I don't know if this is wrong or not, but on the last line you put a full stop after 'end' instead of a semicolon.
Also, "end. writeln('you have used up all of your attempts');" looks like it could be wrong, since all your other "end"s are on their own line. |
Ahhhh...pascal..the language that is fantastic if you don't want to do any input, output or processing:-D. Anyhow, I have got you program to compile (see below). There seems to be a a few bugs in it - if you want me to take a look at them let me know.
* deleted code block - see next post * |
I was rushing before and missed a bit out of the last post. I went to add it and then couldn't resist having a bit of a play:laugh:. Here are the changes:
Code:
program task2a; |
...I was going to say green.
Dicky! |
| All times are GMT +1. The time now is 10:30 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.