Thread: It is but it isnt

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    18

    It is but it isnt

    From what i pulled up and what you all told me the strucsure is more correct than it was but still not write .... I think the thing that might help is to do as told

    turn on warrnings in bev c++ I am trying to find out witch ones do I turn on what do i set acctive?

    her is the current chages. what do you think?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
       int main(int argc, char *argv[])
    {
       char studnam [30]; 
       char grade [1];
       char bye [3];
       int prtrep = 0;
       int score1 = 0;
       int score2 = 0;
       int score3 = 0;
       int score4 = 0;
       int score5 = 0;
       int average = 0;
       
        do while ( strcmp(studnam, bye ) != 0 )
    {
          printf("Please enter the first and last name of the student.\n");
            scanf("%s",studnam);
          printf("Please enter test score 1 for student %d.\n",&studnam);
            scanf("%d",score1); 
          printf("Please enter test score 2 for student %d.\n",&studnam);
            scanf("%d",score2); 
          printf("Please enter test score 3 for student %d.\n",&studnam);
            scanf("%d",score3); 
          printf("Please enter test score 4 for student %d.\n",&studnam);
            scanf("%d",score4); 
          printf("Please enter test score 4 for student %d.\n",&studnam);
            scanf("%d",score5); 
    }
            average = (score1+score2+score3+score4+score5) /5  ;
    {       
     if (average  <= 59)
     printf("grade is 'F'\n.");
     if (average >= 60 <= 69);
     printf ("grade is 'D'.\n");
     if (average <= 70 >= 79)
     printf("grade is 'C'.\n");
     if (average <= 80 <= 89)
     printf("grade is 'B'.\n");   
     if (average <= 90 <= 100)
     printf("grade is 'A'\n");     
    }
    
           printf("Would you like to print the entered informaion?");
           scanf("%d", prtrep);
           printf("1: Print Report");
           printf("2: Exit Program");
    {
           if (prtrep == 2);
           printf("than print file grades record.\n");
           if (prtrep == 1);
           printf("Hit enter to exit program now.\n");
    }       
      
           system("PAUSE");
           return 0;
    }
    also i am wondering if there might just be a better way to get the five test score entries.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Australia - Melbourne
    Posts
    63
    some parts of the code is incorrect

    0. i have never seem the do {}... while () writen like that what i've seem is:
    Code:
    do {
        statements; 
    }
    while (condition) ;
    1. to print a string use %s conversion specification (not %d) and don't place the ampersand (&) infront of the variable in the parameter list. below is a working version.
    Code:
     printf("Please enter test score 1 for student %s.\n", studnam);
    2. ampersand (&) missing infront of the variable names in the scanf functions. below is a working version.
    Code:
    scanf("%d", &score1);
    3. average grade print out should have else before the if after the first if - confused look at code below and need to reformat the condition with the && operator. below is a working version. copy and paste if you must.
    Code:
     if (average < 60) printf("grade is 'F'\n.");
     else if (average > 59 && average < 70) printf ("grade is 'D'.\n");
     else if (average > 69 && average < 80) printf("grade is 'C'.\n");
     else if (average > 79 && average < 90) printf("grade is 'B'.\n");   
     else if (average > 89 && average < 101) printf("grade is 'A'\n");
    4. the code :
    Code:
          
    printf("1: Print Report");
    printf("2: Exit Program");
    should go after
    Code:
    printf("Would you like to print the entered informaion?");
    but before the scanf function.

    4. print report has similar error to above, the extra semicolon should be removed too.
    Code:
           if (prtrep == 2) printf("then print file grades record.\n");
           else if (prtrep == 1) printf("Hit enter to exit program now.\n");
    \n needs to be used in some other places and really no need for the extra braces

    good luck, hope i haven't made any mistakes in my code and language.
    i'm new to c aswell.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    3
    Point 3 can be written:
    Code:
    if (average < 60) printf("grade is 'F'\n.");
     else if (average  < 70) printf ("grade is 'D'.\n");
     else if (average  < 80) printf("grade is 'C'.\n");
     else if (average  < 90) printf("grade is 'B'.\n");   
     else if (average< 101) printf("grade is 'A'\n");

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Australia - Melbourne
    Posts
    63
    Good point. The point to that is only one if ... is executed and the rest igorned

    Also there is no need for the #include <stdlib.h> bit and int argc, char *argv[] as arguments of main.

    That's unless you want to add or edit code later on, which i'm no doubt you will.
    Last edited by peterchen; 01-15-2006 at 04:26 AM. Reason: didn't consider everything

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    well look at your code once again
    Code:
    do while ( strcmp(studnam, bye ) != 0 )
    {
          printf("Please enter the first and last name of the student.\n");
            scanf("%s",studnam);
          printf("Please
    the do while synatx is not correct. thats not the way of using the do - while

    Code:
    do
    {
        ---
        ---
    }while( -exit loop contiotn - ); <-- note: semicolon
    Code:
    strcmp(studnam, bye )
    i dont see any values for the bye to have an exit

    Code:
    scanf("%d",&score1); 
    scanf("%d",&score2); 
    scanf("%d",&score3); 
    scanf("%d",&score4); 
    scanf("%d",&score5);
    forgot to put '&'

    Code:
    system("PAUSE");
    not a good idea to pause the program see FAQ for why not to use systen instead use this

    Code:
    int ch;
    
    while((ch=getchar())!='\n' && ch!=EOF);
    
    getchar();
    ssharish2005

Popular pages Recent additions subscribe to a feed