2014May9 - CPPS - Visual Studio Lab7a.c

1 min read

Deviation Actions

Ongpohhuatiloveu2's avatar
Published:
637 Views
#include<stdio.h>
void main (void)
{
       //Lab7a.c
       int loopCount,mark,total;//declare variables used, refer to bold prints
       char grade;
       total=0;//initialize starting value
       loopCount=0;//initialize loopCount
       while(loopCount<5)//check if loop still required
       {
              printf("Please enter mark for question %d\n",loopCount+1);
              scanf("%d",&mark);
              if(mark<0 || mark>20)
              {
                     printf("You have entered an invalid component mark, try again\n");
                     continue;
              }
              total=total+mark;
              loopCount++;//increment loopCount
       }
       if(total<50)grade='F';
       else if(total<59)grade='D';
       else if(total<69)grade='C';
       else if(total<79)grade='B';
       else grade='A';
       printf("The subject mark is %d and grade is %c\n",total,grade);
}
© 2014 - 2024 Ongpohhuatiloveu2
Comments0
Join the community to add your comment. Already a deviant? Log In