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
  • 9,653
  • 5
  • 43
  • 62
  • Probably you should use `double` variables instead of `int`. – Benjamin Bihler Dec 01 '20 at 14:38
  • Try `pattend=100.0 * nca/nch;` here: [https://ideone.com/NifP3l](https://ideone.com/NifP3l) – drescherjm Dec 01 '20 at 14:53
  • Please put a bit of effort into useful variable names. `nca`, `nch`, `pattend`, `cinnch`, and `cinnca` are completely unclear. Using good variable names is critical, _especially_ when expecting somebody else to read your code. – Chris Dec 01 '20 at 17:25

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.