 # CGPA the Golden Egg!

Limits: 1s, 512 MB

Jenith is a student of CSE of Metropolitan University (MU). Recently her fifth term’s result has been published. She obtained CGPA 4 out of 4. Her classmates ask her to calculate their CGPA. Actually she helps her friends to calculate their CGPA from the first term. Sometimes she feels bore, so she wants to write a program now that will help her friends to calculate their CGPA. As you are a very good programmer she needs your help.

This is a companion discussion topic for the original entry at https://toph.co/p/cgpa-the-golden-egg
``````#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i,c,t;
double a,b,sum,cg,cr;
cin>>n;
for(i=0;i<n;i++)
{
cin>>m;
sum=0;
cr=0;
c=0;
for(int j=0;j<m;j++)
{
cin>>a>>b;
if(a>=80&&a<=100)
{
cg=4.00;
}
else if(a>=75&&a<80)
{
cg=3.75;
}
else if(a>=70&&a<75)
{
cg=3.50;
}
else if(a>=65&&a<70)
{
cg=3.25;
}
else if(a>=60&&a<65)
{
cg=3.00;
}
else if(a>=55&&a<60)
{
cg=2.75;
}
else if(a>=50&&a<55)
{
cg=2.50;
}
else if(a>=45&&a<50)
{
cg=2.25;
}
else if(a>=40&&a<45)
{
cg=2.00;
}
else if(a<40&&a>=0)
{
c++;
}
cr+=b;
sum+=cg*b;
}
if(c>0)
{
if(c==1)
cout<<"Case "<<i+1<<": "<<"Sorry, you have failed in "<<1<<" courses!"<<endl;
else
cout<<"Case "<<i+1<<": "<<"Sorry, you have failed in "<<c<<" courses!"<<endl;
}
else
{
cout<<"Case "<<i+1<<": "<<fixed<<setprecision(2)<<sum/cr<<endl;
}
}
}
``````

what’s the problem this code?

#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,n,c;
double m,a,b,sum,sum1,p;
cin>>n;
for(i=1;i<=n;i++)
{
sum=0,sum1=0,p=0,c=0;
cin>>m;
while(m–)
{
cin>>a>>b;
if(a>=80)
{
p=4b;
}
else if(a>=75)
{
p=3.75
b;
}
else if(a>=70)
{
p=3.50b;
}
else if(a>=65)
{
p=3.25
b;
}
else if(a>=60)
{
p=3b;
}
else if(a>=55)
{
p=2.75
b;
}
else if(a>=50)
{
p=2.50b;
}
else if(a>=45)
{
p=2.25
b;
}
else if(a>=40)
{
p=2*b;
}
sum=sum+b;
sum1=sum1+p;
if(a<40)
{
c++;
}
}
if(c>0)
{
cout<<“Case “<<i<<”: Sorry, you have failed in “<<c<<” courses!”<<endl;
}
else
{
cout<<fixed<<setprecision(2)<<"Case “<<i<<”: "<<sum1/sum<<endl;
}
}
}
???

Your code can’t handle test case (WA) when both mark and credit is a floating number. try this as input:
1
3
79.5
1.5
88
3
100
3