Thread: c program

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    7

    c program

    I have this program that I wrote a few weeks ago:
    Code:
    #include<stdio.h>
    #include<conio.h>
    int main()
    {
      float grade;
      printf("\nEnter Grade:\n");
      scanf("%f", &grade);
      if( grade >= 90)
      printf("Your grade is:A");
      else if ( grade >= 80)
      printf("Your grade: B");
      else if ( grade >= 70)
      printf("Your grade: C");
      else if ( grade >= 60)
      printf("Your grade: D");
      else if ( grade <= 59)
      printf("Your grade: F");
    return 0;
    _getch();
    }
    Now i have to repeat this for 6 students. How do I know which loop to use?

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    Are you sitting in class during a test asking us these questions?

    For, While and Do While Loops in C - Cprogramming.com

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Unless the grade variable can be a floating point number, always use an integer for number variable data types.

    You can use a while loop, but if you know the number of times you need to loop (6 in this case), then a for loop is easiest and clearest.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A development process
    Study carefully what happens at step 5.

    When you have a function to process one student, write a loop to call it 6 times.
    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. Replies: 13
    Last Post: 11-03-2010, 12:45 PM
  2. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM

Tags for this Thread