1,105,625 Community Members

Please Help

Member Avatar
HelpWanted2115
Newbie Poster
11 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
nullptr
Posting Whiz in Training
257 posts since Mar 2012
Reputation Points: 55 [?]
Q&As Helped to Solve: 51 [?]
Skill Endorsements: 2 [?]
 
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.

Member Avatar
ddanbe
Posting Expert
5,364 posts since Oct 2008
Reputation Points: 2,066 [?]
Q&As Helped to Solve: 910 [?]
Skill Endorsements: 46 [?]
Featured
 
0
 

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

Member Avatar
House_of_Dexter
Newbie Poster
21 posts since Oct 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article