0

Ques:

A student will not be allowed to sit in exam if his/her attendence is less than 75%. Take following input from user Number of classes held Number of classes attended. And print percentage of class attended Is student is allowed to sit in exam or not.

MY_solution :

int main()
{
   int nca;
   int nch;
   int pattend;
   cout << "Enter no. of classes held : " << endl;
   cinnch;
   cout << "Enter no. of classes attended : " << endl;
   cinnca;
   pattend = (nca / nch * 100);
   cout << "Percentage attendence : " << pattend << endl;
   if (pattend = 75) {
       cout << "Allowed to Give EXAMS :) " << endl;
   }
   else {
       cout << "NOT ALLOWED! Wasted" << endl;
   }
}

My_output:

**Enter no. of classes held : 100

Enter no. of classes attended : 50

Percentage attendence : 0

NOT ALLOWED! Wasted**

I'm not getting percentage attendance correct .

drescherjm
  • 10,365
  • 5
  • 44
  • 64

1 Answers1

0

Dividing two integers will give an integer result, so in your case 50/100 = 0.

If you want a floating point result, you need to change your variable types to float or double.