Like Tree1Likes

Need HUGE help

This is a discussion on Need HUGE help within the C Programming forums, part of the General Programming Boards category; I'm trying to write a program in which allows the user to input grades in one function, view the grades ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    19

    Need HUGE help

    I'm trying to write a program in which allows the user to input grades in one function, view the grades inputted in another, change the grade in another, and lastly view the grades based off of the low and high that the user puts in. So far, I need help getting the first two functions working (hoping the the other two will come along once i figure these two out.

    I need help getting the grades that are inputted in getgrades to appear in showgrades. I don't know if it's a problem with my grades array or if it is the way that I have those two functions set up. Please help.

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>
    #include<string.h>
    
    
    int getgrades(double *grades);
    int menu(void);
    void showgrades(double *grades);
    
    
    int main(void)
    {
        double grades[100];    
          
    int key, more = 1;
    do
    {
          key = menu();
          switch(key)
          {
          case 1: getgrades(grades); break;
          case 2: showgrades(grades); break;
          case 3: changegrades(); break;
          case 4: findgrades(); break;
          case 5: more = quit(); break;
          default: printf("\nError in selection. Press Enter to Continue\a");
          getchar();
          }
    }
    while(more);
    return 0;
    }
    
    
    int menu()
    {
    system("cls");
    int selection;
    
    printf("1 = Get Grades\n");
    printf("2 = Show Grades\n");
    printf("3 = Change Grades\n");
    printf("4 = Find Grades\n");
    printf("5 = Quit\n");
    
    /*For user selection*/
    printf("\n\nEnter your selection here: ");
    scanf("%d%*c", &selection);
    
    return(selection);
    }
    
    int getgrades(double *grades)
    {
        int count = 0;
         system("cls");
         printf("Enter Grades\n\n");
         
    do
    {
    count++;
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", grades);
    }
    while(*grades > 0);
    printf("%d", count);
    getchar();
    return(count);
    }
    
    
    
    void showgrades(double *grades)
    {
    system("cls");
    int i;
         
         printf("Inputed Grades");
         printf("\n\nPosition_______Grade\n");
         for(i=0; i < 20; i++)
         {
         printf("%d%18.2lf\n", i, *grades);
    }
    printf("Press Enter to Continue");
    getchar();
    }
    
    
    
    
    \* From this point on I plan on figuring it out myself, I need help before this though..."*\
    
    changegrades()
    {
    int position;              
                  
    system("cls");              
    printf("Change Grades \n\n");
    
    do
    {
    printf("Enter the position of the Grade you want to change (or 0 to quit):");
    scanf("%d%*c", &position);
    }
    while(position > 0);
    return(0);
    }
    
    
    findgrades()
    {
    int low, high; 
                
    system ("cls");
    printf("Enter the lowest grade to locate: ");
    scanf("%d%*c", &low);
    printf("Enter the highest grade to locate: ");
    scanf("%d%*c", &high);
    return(0);
    }
    
    
    int quit()
    {
    printf("\nPress Enter to Continue");
    getchar();
    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    do
    {
    count++;
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", grades);
    }
    while(*grades > 0);
    You never change grades (since you are using it as a pointer here), so you're always scanning to the same spot. Why aren't you just treating it like the array it is:
    Code:
    for( count = 0; count < 100; count++ )
    {
        scanf( "stuff", &grade[ count ] );
        ... decide if you want to stop early or not...
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Ok, so now i have this, but how exactly am i supposed to get it to stop when 0 in inputted?

    Code:
    for(count = 0; count < 100; count++)
    {
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", &grades[count]);
    }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Check to see if what you just entered was zero or not.
    Code:
    read input into a temp varaible
    if temp == 0
        break
    else
        array[ count ] = temp

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    I'm a beginner at this kind of stuff, so please bear with my heavy lack of understanding.

    Is this at least on the right track? I don't quite understand how to begin to put input into the temp variable....

    Code:
    for(count = 0; count < 100; count++)
    {
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", &grades[count]);
    if (grades[count] = 0)
        break;
    }

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    = is for assigning a value
    == is for comparing a value


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Oh yeah... Duh. Thanks for that. Now for this next code, how would i get it so the showgrades function does these two things:
    1. Only shows the amount of grades as the user enters in.
    and 2. shows the grades correctly for each one.

    So far, i have this and it's showing ever grade as the first grade input in getgrades

    Code:
    void showgrades(double *grades)
    {
    system("cls");
    int i;
         
         printf("Inputed Grades");
         printf("\n\nPosition_______Grade\n");
         for(i=0; i < 20; i++)
         {
         printf("%d%18.2lf\n", i+1, *grades);
    }
    printf("Press Enter to Continue");
    getchar();
    }

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by zbred View Post
    Ok, so now i have this, but how exactly am i supposed to get it to stop when 0 in inputted?

    Code:
    for(count = 0; count < 100; count++)
    {
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", &grades[count]);
    }
    Code:
    if (grades[count] == 0)
      break;
    However you might want to think about making grades an integer value and switching your exit value to -1

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    I actually need it to be a double for the assignment.

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by zbred View Post
    I actually need it to be a double for the assignment.
    Then your teacher is an idiot... when's the last time someone got 43.6578% on a test?

    Integers are neat, simple, fast and just a whole lot more fun...

    Make your average a float... no problem... but grade scores?
    Abhas likes this.

  11. #11
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Yeah, the teacher is a HUGE idiot. This whole assignment is so difficult.

    I'm still trying to get the showgrades funtion to work... It still isn't working. This is the code for it I have so far. I'm still not able to get it to show the grades correctly in showgrades OR able to get the count put in getgrades to be returned and go to showgrades

    Code:
    getgrades(double *grades, int count)
    {
         system("cls");
         printf("Enter Grades\n\n");
         
    
    do
    {
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", grades);
    count++;
    }
    while (*grades != 0);
    
    printf("The count is %d", count-1);
    printf("\n\nPress Enter to Continue");
    getchar();
    return(0);
    }
    
    
    
    void showgrades(double *grades, int count)
    {
    system("cls");
    int i;
    
         printf("Inputed Grades");
         printf("\n\nPosition_______Grade\n");
       for(i=0; i<count; i++)
         {
         printf("%d%20.2lf\n", i+1, *(grades+i));
    }
    printf("\n\nPress Enter to Continue");
    getchar();
    }

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    do
    {
    printf("Enter Grade or Press 0 to Exit:");
    scanf("%lf%*c", grades);
    count++;
    }
    while (*grades != 0);
    I already told you what you were doing wrong with this type of loop. What I said before didn't just suddenly stop being true.


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Whoops. I'm sort of an idiot sometimes. This is what I got now that I changed it back. but I am having trouble at getting the loop to stop once 0 in put in.

    Code:
    for(count = 0; count < 100; count++)
    {
        printf("Enter Grade or Press 0 to Exit:");
        scanf("%d*c", &grades[count]);
        grades[count] = temp;
        if (temp == 0)
        {
        break;
    }
    else
    {
        grades[count] = temp;
    }
    }

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're doing it backwards. Scan into temp, then check temp, then assign temp if it's not zero. All you are doing is overwriting whatever it is you scanned with whatever was in temp.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    THANK you SO much! I got that now. Still having trouble showing the grades in the showgrades function.

    Code:
    getgrades(double *grades)
    {
         double temp;
         system("cls");
         printf("Enter Grades\n\n");
         
    
    for(count = 0; count < 100; count++)
    {
              
        printf("Enter Grade or Press 0 to Exit: ");
        scanf("%lf*c", &temp);
        if (temp == 0)
        {
        break;
    }
    else
    {
        temp = grades[count];
    }
    }
    
    getchar();
    return(count);
    }
    
    
    
    void showgrades(double *grades, int count)
    {
    system("cls");
    int i;
    
         printf("Inputed Grades");
         printf("\n\nPosition_______Grade\n");
       for(i=0; i<count; i++)
         {
         printf("%d%20.2lf\n", i+1, *(grades+i));
    }
    printf("\n\nPress Enter to Continue");
    getchar();
    }

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 03-02-2011, 07:35 PM
  2. Huge string manipulation problem.
    By jadaces in forum C Programming
    Replies: 24
    Last Post: 07-14-2010, 01:54 PM
  3. near, far and huge pointers
    By roaan in forum C Programming
    Replies: 14
    Last Post: 08-27-2009, 06:15 PM
  4. Calculating prime factor of a huge number.
    By Bakster in forum C Programming
    Replies: 15
    Last Post: 02-20-2009, 12:06 PM
  5. near, far , huge pointers in linux.
    By quickNitin in forum C++ Programming
    Replies: 6
    Last Post: 08-29-2006, 09:40 AM

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