Hello guys, I'm currently having a problem with converting uppercase to lowercase. For example in my code below when a user enters in the class number I'm trying to let them be able to type it in both uppercase and lowercase. Like instead of only being able to type ABC101, they should be able to type aBc101 or abc101 and so forth. And my last problem that I'm having is with letting the user type in their full name while using only one variable instead of three like I have it.

#include <stdio.h>             
#include <string.h>
#include <iostream>



/*+*+*+*+*+*+*+* Function Prototypes *+*+*+*+*+*+*+*/

void WelcomeInfo (void);                                    /* Welcomes the user */
void AskQuestion(void);                                     /* Asks the user a question */
void GetInfo(void);                                         /* Gets the input */
void GetStudentGrade(void);
void NameofStudent(void);       
void PerformCalc(void);                                 /* Performs the calculation */                              
void GradeDisplay(void);
void Totals(void);
void WeightedGrade(void);
void AskQuestion2(void);                                    /* Asks the user a question */
void PrintAStarLine(void);
void TotalPageDisplay(void);

/*+*+*+*+*+*+*+* Variables *+*+*+*+*+*+*+*/




float test1;
float test2;
float project1;
float project2;
float midterm;
float final;
float tests;
float projects;
float midtermexam;
float finalexam;
float studentgrade;


int bonus = 0;
float totalaverage;
int totalstudents;

int studentA = 0;
int studentB = 0;
int studentC = 0;
int studentD = 0;
int studentF = 0;


char courseNumber[10];
char cName;
char cMore;
char firstName[25];
char middleName[25];
char lastName[25];
char StudentfirstName[25];
char StudentmiddleName[25];
char StudentlastName[25];
char studentandgrade;



/*+*+*+*+*+*+*+*^ The Main Module ^*+*+*+*+*+*+*+*/

main()
{   


    cName = 'N'; 


    do
    {
   WelcomeInfo();


   AskQuestion();


   } while ((cName != 'Y') && (cName != 'y'));   


    cMore = 'Y';
    do
    {


    GetInfo(); 
    system("cls");
    NameofStudent();
    system("cls");
    GetStudentGrade();
    system("cls");
    PerformCalc();
    WeightedGrade();
    system("cls");
    GradeDisplay();

    AskQuestion2();



    }while ((cMore != 'N') && (cMore != 'n'));      /* It will loop until user enter N */


    Totals();
    TotalPageDisplay();



    return 0;
}

/*+*+*+*+*+*+*+* Welcomes The User *+*+*+*+*+*+*+*/

void WelcomeInfo (void)
{


    printf("Enter your name please.   ");
    scanf(" %s %s %s", &firstName, &middleName, &lastName); 

    printf("\n\n\n");

    printf("\t\t\t\tWelcome %s %s %s  \n", firstName, middleName, lastName);
    printf("\n\n\n");

    return;
}

/*+*+*+*+*+*+*+* Asks The User A Question *+*+*+*+*+*+*+*/

void AskQuestion(void)
{
    printf("\n\nIs this your name? (Y/N)");                         /* prints the description */
    scanf(" %c", &cName);                                           /* get the input */
    fflush(stdin);                                                  /* flush the CRLF */


    return;
}



/*+*+*+*+*+*+*+* Retrieves The Input *+*+*+*+*+*+*+*/

void GetInfo(void)
{

    /***** Course Number *****/






    printf("\n\nEnter one of the following course numbers. ");
    printf("\n");
    printf("(ABC101, HIS220, HOT707, ECO122, PLE888)\n ");
    scanf(" %s", &courseNumber); 


    if(strcmp(courseNumber,"ABC101")==0)
    {
    printf("\n          Welcome to class ABC101 \n");
    printf("\n\n\n");
    }
    else if(strcmp(courseNumber,"HIS220")==0)
    {
    printf("\n          Welcome to class HIS220 \n");
    printf("\n\n\n");
    }
    else if(strcmp(courseNumber,"HOT707")==0)
    {
    printf("\n          Welcome to class HOT707 \n");
    printf("\n\n\n");
    }
    else if(strcmp(courseNumber,"EC0122")==0)
    {
    printf("\n          Welcome to class ECO122 \n");
    printf("\n\n\n");
    }
    else if(strcmp(courseNumber,"PLE888")==0)
    {
    printf("\n          Welcome to class PLE888 \n");
    printf("\n\n\n");
    }
    else
    {
    printf("\n  That course number does not exist, please try again. \n");
    printf("\n\n\n");
    }
    return;
}

void WeightedGrade(void)
{
    if(strcmp(courseNumber,"ABC101")==0)
    {
    studentgrade = studentgrade + ((tests * .23) + (projects * .27) + (midtermexam * .20) + (finalexam * .30) + (bonus));
    }
    else if(strcmp(courseNumber,"HIS220")==0)
    {
    studentgrade = studentgrade + ((tests * .20) + (projects * .30) + (midtermexam * .25) + (finalexam * .25) + (bonus));
    }
    else if(strcmp(courseNumber,"HOT707")==0)
    {
    studentgrade = studentgrade + ((tests * .25) + (projects * .50) + (midtermexam * .15) + (finalexam * .10) + (bonus));
    }
    else if(strcmp(courseNumber,"EC0122")==0)
    {
    studentgrade = studentgrade = ((tests * .25) + (projects * .25) + (midtermexam * .20) + (finalexam * .30) + (bonus));
    }
    else if(strcmp(courseNumber,"PLE888")==0)
    {
    studentgrade = studentgrade + ((tests * .30) + (projects * .20) + (midtermexam * .25) + (finalexam * .25) + (bonus));
    } 



    return;

}

void NameofStudent(void)
{


    printf("Enter the student's Full Name(First Middle Last) .   ");                        
    scanf( "%s %s %s", &StudentfirstName, &StudentmiddleName, &StudentlastName);
    printf("\n\n\n");


    return;

}
void GetStudentGrade(void)
{
    printf("                     Enter the grades of %s %s %s  \n", StudentfirstName, StudentmiddleName, StudentlastName);
    printf("\n\n\n");


    printf("Enter grade for Test1: ");
    scanf(" %f", &test1);


    printf("Enter grade for Test2: ");
    scanf(" %f", &test2);

    printf("Enter grade for Project1: ");
    scanf(" %f", &project1);

    printf("Enter grade for Project2: ");
    scanf(" %f", &project2);

    printf("Enter grade for Midterm: ");
    scanf(" %f", &midterm);

    printf("Enter grade for Final: ");
    scanf(" %f", &final);

    printf("Number of Bonus Projects: ");
    scanf(" %d", &bonus);


    fflush(stdin);

    return;
}


/*+*+*+*+*+*+*+* Performs All The Calculations *+*+*+*+*+*+*+*/


void PerformCalc(void)
{

    tests = tests + (test1 + test2) / 2;
    projects = projects + (project1 + project2) / 2;
    midtermexam = midtermexam + (midterm);
    finalexam = finalexam + (final);
        if (bonus >= 1 && bonus <= 5)
    {

        bonus = 1;
    }
    else if (bonus >= 6 && bonus <= 9)
    {
        bonus =  3;
    }
    else if (bonus >= 10 && bonus <= 12)
    {
        bonus = 4;
    }
    else if(bonus >= 13)
    {
        bonus = 6;
    }
    else 
    {
        bonus = 0;
    }


    return;

}


void Totals(void)
{   

     if (studentgrade > 90)
        studentA = studentA + 1;

     else if (studentgrade >= 80 && studentgrade <= 89)
        studentB = studentB + 1;

     else if (studentgrade >= 72 && studentgrade <=79)
        studentC = studentC + 1;


     else if (studentgrade >= 70 && studentgrade <= 71)
        studentD = studentD + 1;


     else if (studentgrade <= 69)
        studentF = studentF + 1;




    totalstudents = totalstudents + (studentA + studentB + studentC + studentD + studentF);

    totalaverage = totalaverage + (studentgrade);



    return;

}

void GradeDisplay(void)
{
    printf("Test Scores: %10.3f\n", tests);
    printf("Project Scores: %10.3f\n", projects);
    printf("Midterm Score: %10.3f\n", midtermexam);
    printf("Final Score: %10.3f\n", finalexam);
    printf("Bonus Points: %d\n", bonus);
    printf("Student Grade: %10.3f\n", studentgrade);
    fflush(stdin);  

    return;

}

/*+*+*+*+*+*+*+* Asks The User A Question *+*+*+*+*+*+*+*/

void AskQuestion2(void)
{
    printf("\n\nWould you like to enter in grades again? (Y/N)");       /* print description */
    scanf(" %c", &cMore);                                               /* get the input */
    fflush(stdin);                                                      /* flush the CRLF */


    return ;
}

void PrintAStarLine(void)

{

      printf("******************************************************************************** \n");
      printf("\n\n");

      return;

}

void TotalPageDisplay(void)
{

    system("cls");
    PrintAStarLine();
    printf("\t\t\t\tSchool Grade Totals  \n");
    printf("\n\n");
    PrintAStarLine();
    printf("Grade\t\t\t Total Students  \n", studentandgrade);
    printf("A\t\t\t  %d\n",  studentA);
    printf("B\t\t\t  %d\n",  studentB);
    printf("C\t\t\t  %d\n",  studentC);
    printf("D\t\t\t  %d\n",  studentD);
    printf("F\t\t\t  %d\n",  studentF);
    printf("\n\n");



    printf("__________________________________________________________________________  \n");

    printf("GrandTotal number of Students:                %d\n", totalstudents);
    printf("\n");

    printf("Overall average of all students:            %6.2f\n", totalaverage);
    printf("\n");

    return;

}

In the ctype.h header you can find tolower, toupper, islower, and isupper for working with lower and upper case letters.

some compilers may support strupr() and strlwr() which convert the entire string, but its not standard. You can easily write such a function yourself.

you can use this simple function.

void vStringToUpper( const char *pcInputStr, char *pcOutputStr )
{
     int iLength, iIndex;
     iLength = strlen( pcInputStr );
     
     for( iIndex=0; iIndex<iLength; iIndex++ )
     {
          if( pcInputStr[iIndex]>='a' && pcInputStr[iIndex]<='z' )
                    pcOutputStr[iIndex]=pcInputStr[iIndex]-32; // change to uppercase
          else
                    pcOutputStr[iIndex]=pcInputStr[iIndex];    
     }
}

iLength = strlen( pcInputStr );

Pointer strings always end with a '\0' character so calling strlen to find the end just slows the whole function down. This is a good pattern to get in the habit of using.

for ( i = 0; s[i] != '\0'; ++i ) {
  /* Do stuff with the character */
}

if( pcInputStr[iIndex]>='a' && pcInputStr[iIndex]<='z' )

islower exists because this code doesn't always work. Some character sets have holes in the alphabet characters that aren't a part of the alphabet. Your code gives a false positive on those characters and islower wouldn't.

pcOutputStr[iIndex]=pcInputStr[iIndex]-32; // change to uppercase

This is even worse with the holey character sets because subtracting 32 would give you a completely different character that might or might not even be a letter. That's why toupper exists.

The worst part is that your function doesn't append '\0' to the destination string so it's not really a string. The only time your function works on any platform is if the calling code initializes the destination string to all zeros first.

char *src = "my string";
char dst[10] = {0};

upperCase( src, dst );

It's bad enough that the function relies on the calling code to get the size of the destination string right. You should depend on callers to do the right thing as little as you can because if you don't, they're sure to get it wrong and you'll get blamed for blowing things up. ;)

I'd write it like this instead.

char *upperCase( const char *src, char *dst )
{
  int i;

  for ( i = 0; ( dst[i] = src[i] ) != '\0'; ++i ) {
    if ( islower( dst[i] ) ) {
      dst[i] = toupper( dst[i] );
    }
  }

  return dst;
}

Making sure the source string can be modified is even better because then you don't have the problem of buffer overflow if dst is smaller in size than src.

char *upperCase( const char *src )
{
  char *temp;

  for ( temp = src; *temp != '\0'; ++temp ) {
    if ( islower( *temp ) ) {
      *temp = toupper( *temp );
    }
  }

  return src;
}

Now the calling code has total control of any copies of the string. If it needs one immutable copy then it can handle it outside of your function and you don't have to worry about allocating memory or wondering if the destination string is the right size. You use the source string as the destination string, so it's always the right size. :)

Pointer strings always end with a '\0' character so calling strlen to find the end just slows the whole function down. This is a good pattern to get in the habit of using.

for ( i = 0; s[i] != '\0'; ++i ) {
  /* Do stuff with the character */
}

So what if strlen() adds a few microseconds. That is not a good reason not to use it. Both versions of the loop work as expected so use the one you like best and is easiest for you to understand.

islower exists because this code doesn't always work. Some character sets have holes in the alphabet characters that aren't a part of the alphabet. Your code gives a false positive on those characters and islower wouldn't.

Yes they exist. But the technique used by VatooVatoo works just fine for all the character sets in common use, which is ASCII. Yes, EBCDIC still exists, but it is not in common use outside of IBM mainframes -- generally not a computer people learn on.

This is even worse with the holey character sets because subtracting 32 would give you a completely different character that might or might not even be a letter. That's why toupper exists.

Again, only EBCDIC would be a problem. Therefore, all three of these suggestions are good techniques to know, but not because they are bad. They are just alternatives.

The worst part is that your function doesn't append '\0' to the destination string so it's not really a string. The only time your function works on any platform is if the calling code initializes the destination string to all zeros first.

Absolutely correct. C/C++ by definition does not initialize buffers to 0 when created so there is undoubtedly junk in the string. Even if your compuler does initialize the buffer, do not rely on it -- ever! Most compilers don't.

So what if strlen() adds a few microseconds. That is not a good reason not to use it. Both versions of the loop work as expected so use the one you like best and is easiest for you to understand.

I think avoiding a second pass over the string is a fantastic reason not to use it. Microseconds add up faster than you might expect. Yeah, both versions work as expected, but my version isn't harder and it obviously performs better without any loss of simplicity. I don't see any reason not to use the faster method if there's no trade-off.

Yes they exist. But the technique used by VatooVatoo works just fine for all the character sets in common use, which is ASCII. Yes, EBCDIC still exists, but it is not in common use outside of IBM mainframes -- generally not a computer people learn on.

Okay, how about this? Using islower and toupper makes the code shorter and easier to understand. :) How about if you use toupper, you don't even need to test if it's lower case because toupper returns the same character if there's no conversion to make? I forgot that in my code, but you can simplify it even more to this.

for ( i = 0; ( dst[i] = src[i] ) != '\0'; ++i ) {
  dst[i] = toupper( dst[i] );
}

How is the manual way any better even when the character set is guaranteed to support it?

Again, only EBCDIC would be a problem. Therefore, all three of these suggestions are good techniques to know, but not because they are bad. They are just alternatives.

They're good to know, but not to use. You're taking for granted that you know how it works and expect everyone else to. The whole thing is magic and needs comments to describe what's going on and the possible places when it might fail. But there's a better way that doesn't need comments or disclaimers at all. A bad alternative isn't an alternative. It's just plain poor judgment. ;)

Thanks for replying guys, where would I insert that in my code for the coursenumber to be read either in uppercase or lowercase.

You have to read the course number first, then you can call the function to convert it to upper or lower case.

if ( scanf( " %9s", courseNumber ) != 1 ) {
  /* Handle an I/O error */
}

upperCase( courseNumber );

/* Now courseNumber is upper case */

I think avoiding a second pass over the string is a fantastic reason not to use it. Microseconds add up faster than you might expect.

Something every sane programmer'd do only once, he'd not call strlen for every iteration of the loop but once before entering the loop, saving the result.

Yeah, that's even worse. :D

LoL
Guys I just want to help someone to solve his/her problem and I didnt know this code was very important.

I just write it on my workbench in afew minutes.

I think there is not any missing in my code just one point "putting null at the end of target string" for standard PC with using ANSI C.

here is the new one

void vStringToUpper( const char *pcInputStr, char *pcOutputStr )
{

     int iLength, iIndex;
     iLength = strlen( pcInputStr );
     
     for( iIndex=0; iIndex<iLength; iIndex++ )
     {
          if( pcInputStr[iIndex]>='a' && pcInputStr[iIndex]<='z' )
                    pcOutputStr[iIndex]=pcInputStr[iIndex]-32; 
          else
                    pcOutputStr[iIndex]=pcInputStr[iIndex];    
     }

     pcOutputStr[iIndex]=0x00;

}

NycNessyness you can add it like below:

void GetInfo(void)
{

    /***** Course Number *****/
    


    char tmpCourseNumber[10];

    
    printf("\n\nEnter one of the following course numbers. ");
    printf("\n");
    printf("(ABC101, HIS220, HOT707, ECO122, PLE888)\n ");
    scanf(" %s", &tmpCourseNumber); 
    

    vStringToUpper( tmpCourseNumber, courseNumber );

............

I must confess I am a little confused concerning this part of your question;

And my last problem that I'm having is with letting the user type in their full name while using only one variable instead of three like I have it.

and also these portions of your posted code.

scanf(" %s %s %s", &firstName, &middleName, &lastName);

scanf( "%s %s %s", &StudentfirstName, &StudentmiddleName, &StudentlastName);

scanf(" %s", &courseNumber); 

I thought I answered your question and pointed to you what were wrong with these statements. LINK. What makes you think this is not applicable to your new posted code?

You have introduced another statement into your code that is better to avoid:

fflush(stdin);

This is undefined in the C Standard. Read HERE about it.

Remember this one too about #include <iostream>

Do like I showed you in here
I am going to show you how you can stop using scanf() to read text
input from user, by using instead a function you know already; "getchar()".

/*
 * Avoid_scanf_for_reading_text.c
 */

#include <stdio.h>

char *reads( char *s, size_t size ); /* prototype */

int main( void )
{
    char name[30] = { '\0' };

    /* call to reads */
    reads( name, sizeof name );
    printf( "Obtained input: \"%s\"\n", name );

    getchar();
    return 0;
}


/*
 *  reads will get any ASCII input from user upto the size of the buffer and it will clear any left over in the standard buffer.
 *  parameters:
 *        a pointer to a string
 *        the size of the buffer array
 *  return:
 *        a pointer to a string.
 *
 */
char *reads( char *s, size_t size )
{
    size_t i = 0;

    for(;;)
    {
        int ch = getchar();

        if( ch == '\n' || ch == EOF )
        {
            break;
        }
        if( i < size - 1 )
        {
            *s = ch;
            ++s;
            ++i;
        }
    }
    *s = '\0';
    return s;
}
/* My input/output:
    Hello World
    Obtained input: "Hello World"

    Supercalifragilisticexpialidocious
    Obtained input: "Supercalifragilisticexpialido"
*/

Everytime you want to obtain a text string from user sustitude scanf for this function.

Now, please do read those blue links, before you post again with the same problems.

I am going to show you how you can stop using scanf() to read text

I think a better way is to use fgets() and avoid writing that reads() function.

fgets(name, sizeof(name), stdin);
// remove the trailing '\n' that fgets() might put in the buffer
if( name[strlen(name)-1] == '\n')
    name[strlen(name)-1] = 0;

I think a better way is to use fgets() and avoid writing that reads() function.

fgets(name, sizeof(name), stdin);
// remove the trailing '\n' that fgets() might put in the buffer
if( name[strlen(name)-1] == '\n')
    name[strlen(name)-1] = 0;

fgets() is a nice function to do that. But you don't make any checks for extra characters left in the buffer if the input is longer that the array to hold. Like "Supercalifragilisticexpialidocious" It would have left five extra characters plus the newline behind. By the time you make all the proper checks to avoid that, and discard those extra characters, it is as long to write it as the reads(). That's why I chose getchar() inside a loop with checks.

fgets() is a nice function to do that. But you don't make any checks for extra characters left in the buffer if the input is longer that the array to hold. Like "Supercalifragilisticexpialidocious" It would have left five extra characters plus the newline behind. By the time you make all the proper checks to avoid that, and discard those extra characters, it is as long to write it as the reads(). That's why I chose getchar() inside a loop with checks.

It's actually not that hard. Minor modification to Ancient Dragon's code fixes your concern:

fgets(name, sizeof(name), stdin);
// remove the trailing '\n' that fgets() might put in the buffer
if( name[strlen(name)-1] == '\n')
{
    name[strlen(name)-1] = 0;
}
[b]else
{
    while (getchar() != '\n');
}[/b]

It's actually not that hard. Minor modification to Ancient Dragon's code fixes your concern:

fgets(name, sizeof(name), stdin);
// remove the trailing '\n' that fgets() might put in the buffer
if( name[strlen(name)-1] == '\n')
{
    name[strlen(name)-1] = 0;
}
[B]else
{
    while (getchar() != '\n');
}[/B]

It was not the hardness of it, at all, but I wanted to create a function that the OP could break with, the habit of using scanf() just because it doesn't know all the work that is behind it.

Another function to obtain text input using as the core the beloved C Standard fgets() function.

char *read_s( char *s, size_t size )
{
    if( fgets( s, size, stdin ) != NULL )
    {
        int len = strlen( s ) - 1;
        
        if( *( s + len ) == '\n' )
        {
            *( s + len ) = '\0';
        }
        else
        {
            int ch;
            do
            {
                ch = getchar();
            }
            while( ch != '\n' && ch != EOF );            
        }
    }
    else
    {
        *s = '\0';
    }
    return s;
}

I used the original code you gave me before. Using scanf is required in the current course I'm taking. When I used this function in my program, it worked for getting the user name but had a problem with getting the coursename and the student name. For the coursename it kept spamming enter course name and for student name it will just skip over it. This is how the code looks now. And after I removed the #include <iostream> got an error stating 'system' undeclared.

/*+*+*+*+*+*+*+* Preprocessor Directives *+*+*+*+*+*+*+*/


#include <stdio.h>             
#include <string.h>




/*+*+*+*+*+*+*+* Function Prototypes *+*+*+*+*+*+*+*/

void WelcomeInfo (void);									/* Welcomes the user */
void AskQuestion(void);										/* Asks the user a question */
void GetInfo(void);											/* Gets the input */
void GetStudentGrade(void);
void NameofStudent(void);		
void PerformCalc(void);									/* Performs the calculation */								
void GradeDisplay(void);
void Totals(void);
void WeightedGrade(void);
void AskQuestion2(void);									/* Asks the user a question */
void PrintAStarLine(void);
void TotalPageDisplay(void);

/*+*+*+*+*+*+*+* Variables *+*+*+*+*+*+*+*/




float test1;
float test2;
float project1;
float project2;
float midterm;
float final;
float tests;
float projects;
float midtermexam;
float finalexam;
float studentgrade;


int bonus = 0;
float totalaverage;
int totalstudents;

int studentA = 0;
int studentB = 0;
int studentC = 0;
int studentD = 0;
int studentF = 0;

char cName;
char cMore;

char Name[25];
char courseNumber[10];
char studentName[30];
char studentandgrade;


char newline;


/*+*+*+*+*+*+*+*^ The Main Module ^*+*+*+*+*+*+*+*/

main()
{	


	cName = 'N'; 


	do
	{
   WelcomeInfo();
   
   
   AskQuestion();
	  

   } while ((cName != 'Y') && (cName != 'y'));   
	

	cMore = 'Y';
	do
	{

	
	GetInfo(); 
	system("cls");
	NameofStudent();
	system("cls");
	GetStudentGrade();
	system("cls");
	PerformCalc();
	WeightedGrade();
	system("cls");
	GradeDisplay();
	
	AskQuestion2();
	

									
	}while ((cMore != 'N') && (cMore != 'n'));		/* It will loop until user enter N */
	

	Totals();
	TotalPageDisplay();
	
	
	
	return 0;
}

/*+*+*+*+*+*+*+* Welcomes The User *+*+*+*+*+*+*+*/

void WelcomeInfo (void)
{
	

	printf("Enter your name please.   ");
	scanf( "%[^\n]%c", Name, &newline );
	
	printf("\n\n\n");
	
	printf("\t\t\t\t Welcome %s", Name);
	printf("\n\n\n");

	return;
}

/*+*+*+*+*+*+*+* Asks The User A Question *+*+*+*+*+*+*+*/

void AskQuestion(void)
{
	printf("\n\nIs this your name? (Y/N)");							/* prints the description */
	scanf(" %c", &cName);											/* get the input */
																	/* flush the CRLF */

    
	return;
}



/*+*+*+*+*+*+*+* Retrieves The Input *+*+*+*+*+*+*+*/

void GetInfo(void)
{

	/***** Course Number *****/
	


	

	
	printf("\n\nEnter one of the following course numbers. ");
	printf("\n");
	printf("(ABC101, HIS220, HOT707, ECO122, PLE888)\n ");
	scanf("%[^\n]%c",  courseNumber, &newline); 
		

	if(strcmp(courseNumber,"ABC101")==0)
	{
	printf("\n			Welcome to class ABC101 \n");
	printf("\n\n\n");
	}
	else if(strcmp(courseNumber,"HIS220")==0)
	{
	printf("\n			Welcome to class HIS220 \n");
	printf("\n\n\n");
	}
	else if(strcmp(courseNumber,"HOT707")==0)
	{
	printf("\n			Welcome to class HOT707 \n");
	printf("\n\n\n");
	}
	else if(strcmp(courseNumber,"EC0122")==0)
	{
	printf("\n			Welcome to class ECO122 \n");
	printf("\n\n\n");
	}
	else if(strcmp(courseNumber,"PLE888")==0)
	{
	printf("\n			Welcome to class PLE888 \n");
	printf("\n\n\n");
	}
	else
	{
	printf("\n	That course number does not exist, please try again. \n");
	printf("\n\n\n");
	GetInfo();
	}
	return;
}

void WeightedGrade(void)
{
	if(strcmp(courseNumber,"ABC101")==0)
	{
	studentgrade = studentgrade + ((tests * .23) + (projects * .27) + (midtermexam * .20) + (finalexam * .30) + (bonus));
	}
	else if(strcmp(courseNumber,"HIS220")==0)
	{
	studentgrade = studentgrade + ((tests * .20) + (projects * .30) + (midtermexam * .25) + (finalexam * .25) + (bonus));
	}
	else if(strcmp(courseNumber,"HOT707")==0)
	{
	studentgrade = studentgrade + ((tests * .25) + (projects * .50) + (midtermexam * .15) + (finalexam * .10) + (bonus));
	}
	else if(strcmp(courseNumber,"EC0122")==0)
	{
	studentgrade = studentgrade = ((tests * .25) + (projects * .25) + (midtermexam * .20) + (finalexam * .30) + (bonus));
	}
	else if(strcmp(courseNumber,"PLE888")==0)
	{
	studentgrade = studentgrade + ((tests * .30) + (projects * .20) + (midtermexam * .25) + (finalexam * .25) + (bonus));
	} 



	return;

}
	
void NameofStudent(void)
{

	
	printf("Enter the student's Full Name(First Middle Last) .   ");						
	scanf( "%[^\n]%c", studentName, &newline );
	printf("\n\n\n");


	return;

}
void GetStudentGrade(void)
{
	printf("                     Enter the grades of %s   \n", studentName);
	printf("\n\n\n");
	

	printf("Enter grade for Test1: ");
	scanf(" %f", &test1);
	

	printf("Enter grade for Test2: ");
	scanf(" %f", &test2);

	printf("Enter grade for Project1: ");
	scanf(" %f", &project1);

	printf("Enter grade for Project2: ");
	scanf(" %f", &project2);

	printf("Enter grade for Midterm: ");
	scanf(" %f", &midterm);

	printf("Enter grade for Final: ");
	scanf(" %f", &final);

	printf("Number of Bonus Projects: ");
	scanf(" %d", &bonus);



	return;
}


/*+*+*+*+*+*+*+* Performs All The Calculations *+*+*+*+*+*+*+*/


void PerformCalc(void)
{
	
	tests = tests + (test1 + test2) / 2;
	projects = projects + (project1 + project2) / 2;
	midtermexam = midtermexam + (midterm);
	finalexam = finalexam + (final);
		if (bonus >= 1 && bonus <= 5)
	{

		bonus = 1;
	}
	else if (bonus >= 6 && bonus <= 9)
	{
		bonus =  3;
	}
	else if (bonus >= 10 && bonus <= 12)
	{
		bonus = 4;
	}
	else if(bonus >= 13)
	{
		bonus = 6;
	}
	else 
	{
		bonus = 0;
	}


	return;

}


void Totals(void)
{	

	 if (studentgrade > 90)
		studentA = studentA + 1;

	 else if (studentgrade >= 80 && studentgrade <= 89)
		studentB = studentB + 1;
	
	 else if (studentgrade >= 72 && studentgrade <=79)
		studentC = studentC + 1;
	

	 else if (studentgrade >= 70 && studentgrade <= 71)
		studentD = studentD + 1;
	

	 else if (studentgrade <= 69)
		studentF = studentF + 1;

	


	totalstudents = totalstudents + (studentA + studentB + studentC + studentD + studentF);
 
	totalaverage = totalaverage + (studentgrade);



	return;

}

void GradeDisplay(void)
{
	printf("Test Scores: %10.3f\n", tests);
	printf("Project Scores: %10.3f\n", projects);
	printf("Midterm Score: %10.3f\n", midtermexam);
	printf("Final Score: %10.3f\n", finalexam);
	printf("Bonus Points: %d\n", bonus);
	printf("Student Grade: %10.3f\n", studentgrade);
	fflush(stdin);	

	return;

}

/*+*+*+*+*+*+*+* Asks The User A Question *+*+*+*+*+*+*+*/

void AskQuestion2(void)
{
	printf("\n\nWould you like to enter in grades again? (Y/N)");		/* print description */
	scanf(" %c", &cMore);												/* get the input */
	fflush(stdin);														/* flush the CRLF */

    
	return ;
}

void PrintAStarLine(void)

{

	  printf("******************************************************************************** \n");
      printf("\n\n");

	  return;
	
}

void TotalPageDisplay(void)
{
	
	system("cls");
	PrintAStarLine();
	printf("\t\t\t\tSchool Grade Totals  \n");
	printf("\n\n");
	PrintAStarLine();
	printf("Grade\t\t\t Total Students  \n", studentandgrade);
	printf("A\t\t\t	 %d\n",  studentA);
	printf("B\t\t\t	 %d\n",  studentB);
	printf("C\t\t\t	 %d\n",  studentC);
	printf("D\t\t\t	 %d\n",  studentD);
	printf("F\t\t\t	 %d\n",  studentF);
	printf("\n\n");



	printf("__________________________________________________________________________  \n");

	printf("GrandTotal number of Students:				  %d\n", totalstudents);
	printf("\n");

	printf("Overall average of all students:			%6.2f\n", totalaverage);
	printf("\n");

	return;

}

Using scanf is required in the current course I'm taking.

Did your instructor mention that
1) scanf("%s",strval); will only read up to whitespace, so if you entered John Doe all that was read is John -- and Doe is left in the buffer for the next scanf() ?

2) scanf("%d", intval); leave junk in the buffer for the next scanf() , so the following read may fail? Especially if you are reading a character string next?

Here's the beginning of a series on scanf() and why it should be avoided. I understand you can't avoid it in this case, but at least you will know what the pitfalls are so you can (maybe) program around them.

I'd be interested in what your instructor has to say about this series, if you show it to him/her.

IUsing scanf is required in the current course I'm taking. When I used this function in my program, it worked for getting the user name but had a problem with getting the coursename and the student name. For the coursename it kept spamming enter course name and for student name it will just skip over it. This is how the code looks now.

Yeap, it sounds like the right behaviour for scanf. There are many reasons why you have been warned not to use it. Believe it or not, the behaviour of scanf is different according of the user input.
Hopefully, the requirement of using that function in your course is to teach you why not to use it.

I And after I removed the #include <iostream> got an error stating 'system' undeclared.

The function system() is prototyped in the header file <stdlib.h>. You need to include it at the beginning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.