# Exercise problem.Score mark program.

Page 1 of 1

## 5 Replies - 2371 Views - Last Post: 11 December 2012 - 02:45 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=303464&amp;s=6665da10a996e852900978943d038f10&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mikelino

• New D.I.C Head

Reputation: 1
• Posts: 25
• Joined: 03-November 12

# Exercise problem.Score mark program.

Posted 10 December 2012 - 01:04 PM

```//WAP to print Grade of a Student
#include<stdio.h>

int main(void)
{
int s,a,b,c,d,e;

a=(s>=90);
b=(s>=80 && s<=89);
c=(s>=70 && s<=79);
d=(s>=60 && s<=69);
e=(s<60);

do
{
printf("\nEnter score:\n");
scanf("%d",&s);

if (s<0 || s>100)
printf("impossible score\n");
else if(s>=90)
printf(" \n  grade  A ");
else if(s>=80 && s<=89)
printf(" \n grade B");
else  if(s>=70 && s<=79)
printf(" \n grade C ");
else if(s>=60 && s<=69)
printf(" \n grade D ");
else if(s<60)
printf(" \n grade E ");

}while (s<0 || s>100);

printf("score results:\n");
printf("A  : %d" ,a);
printf("B  : %d" ,B)/>;
printf("C  : %d" ,c);
printf("D  : %d" ,d);
printf("E  : %d" ,e);

return 0;

}

```

Sorry,im a newbie and fail in executing the solution for the above exercise.The question require to use do-while and print out the result upon a negative entry or any entry more than 100.Can someone helps by providing some guide?

Is This A Good Question/Topic? 0

## Replies To: Exercise problem.Score mark program.

### #2 Martyr2

• Programming Theoretician

Reputation: 4925
• Posts: 13,317
• Joined: 18-April 07

## Re: Exercise problem.Score mark program.

Posted 10 December 2012 - 01:35 PM

Well what you got there should loop if the score is less than 0 or greater than 100. The problems I see here is that for some reason you are setting your variables at the top to condition statements. I think you want to set those to zero. Then in each if/else if increment the count.

```s = a = b = c = d = e = 0;

do
{
printf("\nEnter score:\n");
scanf("%d",&s);

if (s<0 || s>100) {
printf("impossible score\n");
}
else if(s>=90) {
printf(" \n  grade  A ");
a++;
}
else if(s>=80 && s<=89) {
printf(" \n grade B");
b++;
}
else  if(s>=70 && s<=79) {
printf(" \n grade C ");
c++;
}
else if(s>=60 && s<=69) {
printf(" \n grade D ");
d++;
}
else if(s<60) {
printf(" \n grade E ");
e++;
}

}while (s<0 || s>100);

```

Here you see at as each grade is calculated, it increments the appropriate variable by 1. Then at the end you can print out each variable (like you have there) and it should give you the counts of each grade.

### #3 mikelino

• New D.I.C Head

Reputation: 1
• Posts: 25
• Joined: 03-November 12

## Re: Exercise problem.Score mark program.

Posted 10 December 2012 - 02:23 PM

you saying is just as my tutors but i don't get it.
the program prompt user to entry the marks and i did set variables to 0 before but when result print out all is 0.I have no problem in determine it is grade a or grade b but don't know how to code with the result section.Lets say you got marks 87,77,57...the layout should be :
a 1
b 1
c 1

Anyway i don catch why use increment as my knowledge still there as increment is for increasing something and decreasing something.
Is it here means it 87,77,57,will become 97,87,67??
I know my stupidity is unlimited while creative is limited.
Hope guide.

### #4 mikelino

• New D.I.C Head

Reputation: 1
• Posts: 25
• Joined: 03-November 12

## Re: Exercise problem.Score mark program.

Posted 10 December 2012 - 10:21 PM

```//WAP to print Grade of a Student
#include<stdio.h>

int main()
{
int s,a,b,c,d,e;

a=0;
b=0;
c=0;
d=0;
e=0;

do
{
printf("\nEnter score:\n");
scanf("%d",&s);

if (s<0 || s>100){
printf("impossible score\n");
}
else if(s>=90){
printf(" \n  grade  A ");
a++;
}
else if(s>=80 && s<=89){
printf(" \n grade B");
b++;
}
else  if(s>=70 && s<=79){
printf(" \n grade C ");
c++;
}
else if(s>=60 && s<=69){
printf(" \n grade D ");
d++;
}
else if(s<60){
printf(" \n grade E ");
e++;
}
}while (s<0 || s>100);

printf("\nScore results:\n");
printf("A  : %d\n" ,a);
printf("B  : %d\n" ,B)/>;
printf("C  : %d\n" ,c);
printf("D  : %d\n" ,d);
printf("E  : %d\n" ,e);

getch();
return 0;

}

```

ok, i get what you means, but now the problem is not result but do-while loop as it should keep running until a negative or more than 100 marks entry only then it will stop.The do-while loop only run for 1 time only so far.

• D.I.C Lover

Reputation: 331
• Posts: 1,168
• Joined: 01-April 11

## Re: Exercise problem.Score mark program.

Posted 10 December 2012 - 10:54 PM

```while(s>0 && s<101);

```

Is what you need.

### #6 mikelino

• New D.I.C Head

Reputation: 1
• Posts: 25
• Joined: 03-November 12

## Re: Exercise problem.Score mark program.

Posted 11 December 2012 - 02:45 AM

LOL, actually the mentor have shown me the hints before just i too stupid didn't notice about it.
anyway thanks a lot.