Thread: I don't understand what's wrong. HELP!

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    2

    I don't understand what's wrong. HELP!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    int main{
    	int q1, q2, q3, qav, mid, fe, fg;
    	
    	printf("\nEnter Quiz 1:");
    	scanf("%d", &q1);
    	printf("\nEnter Quiz 2:");
    	scanf("%d", &q2);
    	printf("\nEnter Quiz 3:");
    	scanf("%d", &q3);
    	
    	qav = ((q1+q2+q3)/3)*10;
    	
    	printf("\nEnter Midterm Score:");
    	scanf("%d",&mid);
    	printf("\nEnter Final Exam Score:");
    	scanf("%d",&fe);
    	
    	fg = 0.5*fe + 0.25*mid +0.25*qav;
    	
    	scanf("%d",&fg);
    	
    	if ((fg>=90) && (fg<=100))          
    		printf("A\n");
    		
    	else 
    	if ((fg>=80) && (fg<90))
    		printf("B\n");
    	
    	else 
    	if ((fg>=70) && (fg<80))
    		printf("C\n");
    	
    	else 
    	if ((fg>=60) && (fg<70))
    		printf("D\n");
    		
    	else
    		printf("\nF");
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > scanf("%d",&fg);
    Why are you reading a value into fg, when you've already calculated it on the previous line?

    > qav = ((q1+q2+q3)/3)*10;
    Beware of rounding errors caused by integer division rounding down.
    If there is no risk of overflow, it's better to multiply then divide.

    > I don't understand what's wrong.
    You also need to say specifically how reality differs from expectation.
    Just saying "it's wrong" doesn't tell us what your idea of "it's right" is supposed to look like.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i don't understand what's wrong
    By eduarda2 in forum C Programming
    Replies: 3
    Last Post: 06-14-2014, 02:46 PM
  2. can someone help i don't understand what went wrong
    By chekbob in forum C Programming
    Replies: 4
    Last Post: 11-15-2013, 01:12 PM
  3. Don't understand what's wrong
    By AndreyS10 in forum C++ Programming
    Replies: 3
    Last Post: 11-25-2011, 11:41 AM
  4. Can't understand what I'm doing wrong.
    By agentxx04 in forum C Programming
    Replies: 11
    Last Post: 10-22-2004, 07:53 PM
  5. I don't understand what i'm doing wrong..
    By knutso in forum C Programming
    Replies: 4
    Last Post: 03-15-2002, 07:37 AM

Tags for this Thread