While Loop

This is a discussion on While Loop within the C Programming forums, part of the General Programming Boards category; #include <stdio.h> int main() { char A, B, C, D, E; char AllCredit, CreditAttempt; float GPA, GpaCalc; char Grades = ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    While Loop

    #include <stdio.h>

    int main()


    {

    char A, B, C, D, E;
    char AllCredit, CreditAttempt;
    float GPA, GpaCalc;

    char Grades = 'A', 'B', 'C', 'D', 'E';
    int Points = '4','3','2','1','0';

    A = 4;
    B = 3;
    C = 2;
    D = 1;
    E = 0;

    GPA = Points * Grades;
    AllCredit = GPA / CreditAttempt;


    { Grades = getchar();
    while (Grades = getchar() != "\n")
    {
    putchar(Grades);
    Grades = getchar();
    }
    }
    return 0;

    }

    Here is my code. I want to find out if I there is a way I could use a loop to get ABCDE and 01234 in the loop so that it prints out
    something like A4C2B3B3. I know I have a problem with Grades and Points up there, I am right now trying to find out how I could use make it so that when the letter A is pressed I get a 4 to come up and or manually enter numbers so that the program can recognize the all the numbers and print out GPA is 3.24 or 4.00.

    Thank You Very much in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    Ok, a few bits to get you started

    This should allow you to type 'A' and get '4' printed - and extending the idea is pretty easy...

    Code:
    int main ( ) {
        int grades;
        while ( (grades=getchar()) != '\n' ) {  // note the extra ()
            if ( grades == 'A' ) putchar( '4' );
        }
    }
    > char Grades = 'A', 'B', 'C', 'D', 'E';
    > int Points = '4','3','2','1','0';
    If you need to do something like this, you should be looking at arrays. For instance, what you have written will only assign 'A' to Grades, the rest of the letters are thrown away.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    24

    Angry I think you need to study a lot more....

    To do what you want to do is nothing but forces you to study a lot about Arrays, characters, Set of characters (String), declaration of variables, differences between integer and character.....
    RaHaTk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 03:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 01:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21