1.11M Members

Please Help

 
0
 

Ok, I know you guys don't really just give away the answer to the whole problem like that. But I really can't figure this one out.... The question states: The following represents some sample scores obtained by students in a test: 5,4,7,10,0,6,0,1,9,6,8,999. 999 is the dummy value which terminates the data. Write a program to read in any data in the above format and print the number of students scoring zeros and tens. This is what I have so far:

program zeros_tens;

uses wincrt;

var num,count_zero,count_ten:integer;

Begin

 count_zero:=0;
 count_ten:=0;
 readln(num);
 While num<>999 do
 readln(num);
 IF num=0 then
    count_zero:=count_zero+1;
 IF num=10 then
    count_ten:=count_ten+1;
 Writeln('The number of zero(s) is equal to: ',count_zero);
 Writeln('The number of tens is equal to: ',count_zero);

End.

 
0
 

You need to put begin and end in your while loop.

While num <> 999 do
begin
  // code for the loop goes here
  //
end;

Also line 3 isn't needed.
I'll leave you to work out the rest.

 
0
 

Also: have a close look at line 10 and line 11 of your above code.

 
0
 

Also...since you know that you are always going to have a value in num...

You can use Repeat instead of While...

count_zero:=0;
count_ten:=0;

Repeat
  readln(num);
  IF num=0 then
    inc(count_zero);
  IF num=10 then
    inc(count_ten);
until Num = 999;

Also there is a bug in your old code...

readln(num); // <-- you read a value and put the value in the variable num
While num<>999 do //<-- you check if num is not 999
readln(num);//hmmm...what happens to num here? Error Wil Robinson...Error!!!
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article