5 Replies - 1278 Views - Last Post: 11 December 2012 - 02:45 AM Rate Topic: -----

#1 mikelino  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • 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.

:)
Was This Post Helpful? 1
  • +
  • -

#3 mikelino  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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. :withstupid:
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 :
Grade num
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?? :withstupid:
I know my stupidity is unlimited while creative is limited. :nottalkingtoyou:
Hope guide.
Was This Post Helpful? 0
  • +
  • -

#4 mikelino  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

#6 mikelino  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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. :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1