CGPA the Golden Egg!

Jenith is a student of CSE of Metropolitan University (MU). Recently her fifth term’s result has bee…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#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=4*b;
            }
            else if(a>=75)
            {
                p=3.75*b;
            }
            else if(a>=70)
            {
                p=3.50*b;
            }
            else if(a>=65)
            {
                p=3.25*b;
            }
            else if(a>=60)
            {
                p=3*b;
            }
            else if(a>=55)
            {
                p=2.75*b;
            }
            else if(a>=50)
            {
                p=2.50*b;
            }
            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

Vaia 1 ta fail er jonno course hobe courses na… :grin:

I am getting runtime error on Case no 21 , What might be problem in my code bellow?

def gpacalc(marks,credit):

    gpc=0

    if marks>=80 and marks<=100:

        gp=4.00

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    if marks>=75 and marks<80:

        gp=3.75

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    

    if marks>=70 and marks<75:

        gp=3.50

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    if marks>=65 and marks<70:

        gp=3.25

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    if marks>=60 and marks<65:

        gp=3.00

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    if marks>=55 and marks<60:

        gp=2.75

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    if marks>=50 and marks<55:

        gp=2.50

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    

    if marks>=45 and marks<55:

        gp=2.25

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

    if marks>=40 and marks<45:

        gp=2.00

        gpc=float(gpc)

        gpc=gp*credit

        return gpc

t=int(input())

for i in range(t):

    total_credit=0

    count=0

    sumation=0

    gpc=0

    course=int(input())

    for j in range(1,course+1):

        marks,credit=map(float,input().split())

        total_credit+=credit

        if marks>=40 and marks<=100:

            sumation=(sumation+gpacalc(marks,credit))

            

            gpa=sumation/total_credit

        

        else:

            count+=1

    if count==0:

        print("Case {0}: {1:.2f}".format(i+1,gpa))

    elif count==1:

        print("Case {}: Sorry, you have failed in 1 course!".format(i+1))

    else:

        print("Case {0}: Sorry, you have failed in {1} courses!".format(i+1,count))
1 Like
import java.text.DecimalFormat;
import java.util.Scanner;

/**
 *
 * @author Md Rifat
 */
public class CGPAthGoldenEgg {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int T=sc.nextInt();
        float m,n;
        for (int i =1; i <=T; i++) {
            int C=sc.nextInt();
            float sum=0;
            float cradet=0;
            int course=0,fail=0;
            for (int j = 0; j <C; j++) {
                m=sc.nextFloat();
                n=sc.nextFloat();
                course++;
               if((m>=0)&&(m<=100)&&(n>=1)){
                    if((m>=80)&&(m<=100)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(4.00)*(float)(n);
                }else if((m>=75)&&(m<80)){
                    cradet=(float)(cradet+n);
                    sum=(float) sum+(float)(3.75)*(float)(n);
                }else if((m>=70)&&(m<75)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(3.50)*(float)(n);
                }else if((m>=65)&&(m<70)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(3.25)*(float)(n);
                }else if((m>=60)&&(m<65)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(3.00)*(float)(n);
                }else if((m>=55)&&(m<60)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(2.75)*(float)(n);
                }else if((m>=50)&&(m<55)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(2.50)*(float)(n);
                }else if((m>=45)&&(m<50)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(2.25)*(float)(n);
                }else if((m>=40)&&(m<45)){
                    cradet=(float)(cradet+n);
                    sum=(float)sum+(float)(2)*(float)(n);
                }else{
                    fail++;
                }
               }else{
                   System.exit(0);
               }
            }
            if(fail>0){
                if(fail==1){
                    System.out.println("Case "+i+": Sorry, you have failed in 1 course!");
                }else{
                    System.out.println("Case "+i+": Sorry, you have failed in "+fail+" courses!");
                }
            }else{
               
                float result=sum/cradet;
                System.out.println("Case "+i+": "+new DecimalFormat("0.00").format(result));
               
            }
           
        }
    }
}

whats the problem :nauseated_face:

The problem states what to print if you failed any courses. However, it doesn’t state that “course” needs to be pluralized (“course” if 1 fail, “courses” if > 1). Please update the problem statement.

Wrong answer on 21 test case. please help me :cry:

def gpacalc(marks,credit):
	if 80 <= marks <=100: gp = 4.00
	elif 75 <= marks <80: gp = 3.75
	elif 70 <= marks <75: gp = 3.50
	elif 65 <= marks <70: gp = 3.25
	elif 60 <= marks <65: gp = 3.00
	elif 55 <= marks <60: gp = 2.75
	elif 50 <= marks <55: gp = 2.50
	elif 45 <= marks <55: gp = 2.25
	elif 40 <= marks <45: gp = 2.00
	gpc=gp*credit
	return gpc

t=int(input())
results=[]
for i in range(t):
	total_credit=0
	count=0
	sumation=0
	course=int(input())
	for j in range(course):
		marks,credit=map(float,input().split())
		total_credit+=credit
		if 40 <= marks<=100:
			sumation+=gpacalc(marks,credit)
			gpa=sumation/total_credit
		else:
			count+=1

	if count==0:
		results.append("Case {0}: {1:.2f}".format(i+1,gpa))
	elif count==1:
		results.append("Case {0}: Sorry, you have failed in {1} course!".format(i+1,count))
	else:
		results.append("Case {0}: Sorry, you have failed in {1} courses!".format(i+1,count))

for result in results:
	print(result)
1 Like

It seems there was a bug in Toph that was causing your submission verdict to appear as Wrong Answer. The bug has been fixed. Your actual verdict is Runtime Error. Your submission has been rejudged.

Hope that helps! Sorry for the confusion.

#include <stdio.h>

int main() {
	int t,c, fail=0, i=1;
	double m,n, total_cr=0.0, total_marks=0.0;
	scanf("%d", &t);
	while(t--){
		total_marks = 0.0;
		total_cr=0.0;
		scanf("%d", &c);
		while(c--){
			scanf("%lf%lf", &m,&n);
			
			if(m>=80){
				total_marks = total_marks + n * 4.00;
			}
			else if(m>=75){
				total_marks = total_marks + n * 3.75;
			}
			else if(m>=70){
				total_marks = total_marks + n * 3.50;
			}
			else if(m>= 65){
				total_marks = total_marks + n * 3.25;
			}
			else if(m>= 60){
				total_marks = total_marks + n * 3.00;
			}
			else if(m>= 55){
				total_marks = total_marks + n * 2.75;
			}
			else if(m>= 50){
				total_marks = total_marks + n * 2.50;
			}
			else if(m>= 45){
				total_marks = total_marks + n * 2.25;
			}
			else if(m>= 40){
				total_marks = total_marks + n * 2.00;
			}
			else if(m<40){
			 	//total_marks = total_marks + n * 0.00;
				fail++;
			}
			total_cr += n;
		}
		//printf("total cr : %.2lf\n", total_cr);
		
		if(fail==0){
			printf("Case %d: %.2lf\n",i++, total_marks/total_cr );
		}else if (fail == 1){
			printf("Case %d: Sorry, you have failed in 1 course!",i++);
		}else{
			printf("Case %d: Sorry, you have failed in %d courses!",i++, fail);
		}
	}
	
	return 0;
}

---------> Why 21 test Case is not passing?

@Fariha.Brotecs One issue that I can see in your code is that your second and third printfs do not have “\n” at the end. All your cases will end up appearing on the same line with no space in-between.

Thanks! It worked @hjr265

1 Like