Je rencontre un problème avec mon code. Cela commence bien mais quand vous demandez à l'utilisateur de saisir l'entrée au début, il ne passera pas sur l'instruction if. Comment puis-je réparer cela. J'ai essayé des tas pour contourner ceci et finalement l'ai eu pour lire des données mais continuellement dire que c'est invalide.Code ne bouge pas Lire
PROGRAM AT3 (input, output);
uses crt, math;
CONST
band6 = 90;
band5 = 80;
band4 = 70;
band3 = 60;
band2 = 50;
VAR
Studname : array of string;
studmark : array of integer;
flag : boolean;
studinfo : text;
input : string;
count : integer;
num : integer;
input2: integer;
highmark, lowmark : integer;
median, average : integer;
BEGIN
lowmark := 100;
highmark := 0;
median := 0;
ASSIGN (Studinfo, 'ExamResults.txt');
flag := false;
WRITELN('welcome to the Band generator.');
WRITELN('To enter student results, please enter the number of students. To see class statistics, please type zzz. To clear the screen type clear screen. And to exit the program, type exit');
While flag = false DO
ReadLN (input);
IF input = 'zzz' THEN
WHILE not EOF(Studinfo) DO
BEGIN
WRITELN(studinfo);
END;
IF input = 'exit' THEN
Flag := true;
IF input = 'clear screen' THEN
CLRSCR
ELSE
if input2 <> 0 THEN
num := input2
ELSE
WRITELN('Please enter a valid number.');
FOR count := 0 to num-1 DO
BEGIN
WRITELN('Please enter name of student', count);
read(studname[count]);
WRITE(studinfo, studname[count]);
WRITELN('Please enter mark of student', count, 'out of 100 (nearest whole number)');
read(studmark[count]); write(studinfo, studmark[count]);
IF studmark[count] >=band6 THEN
WRITELN(studinfo, 'band6');
IF studmark[count] >=band5 THEN
WRITELN(studinfo, 'band5');
IF studmark[count] >=band4 THEN
WRITELN(studinfo, 'band4');
IF studmark[count] >=band3 THEN
WRITELN(studinfo, 'band3');
IF studmark[count] >=band2 THEN
WRITELN(studinfo, 'band2');
IF studmark[count] <band2 THEN
WRITELN(studinfo, 'band1');
IF studmark[count] >= highmark THEN
highmark := studmark[count];
IF studmark[count] <= lowmark THEN
lowmark := studmark[count];
END;
median := highmark MOD 2;
CLOSE(studinfo);
END.
"il ne bougera pas sur l'instruction if" qui 'déclaration if' voulez-vous dire exactement? BTW, il existe plusieurs autres problèmes avec votre code, par exemple. votre "Assign (Studinfo, 'ExamResults.txt')" doit être suivi immédiatement de "Rewrite (Studinfo)". Aussi, quelle version de Pascal utilisez-vous? – MartynA
Hmmm ... ce code ressemble astucieusement au code écrit par l'utilisateur ** LeCarloVC ** (puis supprimé à nouveau), hier. Il a également eu les mêmes problèmes et cette chose «si marque/groupe». Aussi utilisé les mots-clés majuscules (la plupart du temps) et même cette '' zzz '' = fin de l'idée de programme. –
L'indentation seule ne définit pas les blocs en Pascal. Vous avez besoin de 'begin' et' end' pour les blocs multi-instructions. – lurker