Hi i'm new to C++ and have made a grading system application. The application works, but I would prefer to use one variable for student name instead of two seperate variables, but when I try to do this it skips to the next line of code when I run the application. I have tried cin >> and cin.getline, but before I can enter the students name it jumps to enter assignment result.

//Student grading system
#include <iostream>
#include <stdlib.h>

using std::cout;  
using std::cin;
using std::endl;

char con;          
int total[6];
int Ac;
char course[25];
char studentfirstname[6][25]; 
char studentsurname[6][25];   
int Assign1[6];
int Assign2[6];
char grade[6][15];    

void Grade_Function(int total){            
	if ((total >=0) && (total <=39)) {
		cout << "Fail" << endl;
	}
	if ((total >=40) && (total <=59)) {
		cout << "Pass" << endl;
	}
	if ((total >=60) && (total <=79)) {
		cout << "Merit" << endl;
	}
	if ((total >=80) && (total <=100)) {
		cout << "Distinction" << endl;
	}
}

int main (void)     

{
char indicator;      

	cout << "\n\t***************************************************************";       
		  cout << endl;
		  cout << " " ;
		  cout << endl;
			
	      cout << "\t\tWelcome to the Student Grading System "
			  << "\n\t\tThis is a student grading system"
			  << "\n\t\tEnter the course, student name and assignment"
			  << "\n\t\tresult to find out the grade for each student";
		  cout << endl;
		  cout <<"\n\t***************************************************************" << endl;
		 
		 cout << endl;

		 cout << "\n\t\tPress c to continue to the grading system: ";    
                                                                        
		 cin >> indicator;                                        
		 if ((indicator == 'c')|| (indicator == 'C'))             
		 {
		  system ("CLS");                                       
		 }
		 else 
		 {
			 return 0;
		 }
		  while (true)                                 
		  {
		  
		 cout << "\nEnter The Course: " << endl;       
         cin >> course;                              
			 for (Ac = 0; Ac < 6; Ac++)       
			 {
		         
		  cout << "\nEnter Students First Name: " << endl; 
		  cin >> studentfirstname[Ac];             

		  cout << "\nEnter students surname: " << endl;
		  cin >> studentsurname[Ac];
   
		  cout << "\nPlease Enter Assignment 1 result: " << endl;   
		  cin >> Assign1[Ac];                                   
		
		  cout << "\nPlease Enter Assignment 2 result: " << endl;    
		  cin >> Assign2[Ac];
  
		 total[Ac] = Assign1[Ac] + Assign2[Ac];       
			 					 }
			 
				 system("CLS"); 
				 cout << "********************************************************"
			 << "\n\n\t\tCourse Name: "         
					 << course << "\n"
					 << "********************************************************";
					 cout << "\nStudent Name \t\t\tGrade\n"
						 << "________________________________________________________\n";
             for (Ac = 0; Ac < 6; Ac++)        
			 {
				       
					cout << studentfirstname[Ac] << " " << studentsurname[Ac] << "\t\t\t";   
				 
                 Grade_Function(total[Ac]);  
			 }
			 cout << "********************************************************";
				 
		cout << "\n\nIf you want to add another six students press Y to continue."  
				 << "\nElse press any key to exit" << endl;                         
			 cin >> con;                                                   
			if ((con == 'y')|| (con == 'Y'))                       
			 {
				 Ac = 0;                       
			 }
			else 
			{
			cout << "\n\nThankyou for using the student grading system" << endl;
				system("PAUSE");    
				break;        
			
			 return 0;	
		} 
		}
}

See http://www.cplusplus.com/reference/iostream/istream/get/ you'll want the third one down that takes a streamsize (there's an example at the bottom of the page but its got some error checking that you can probably put on hold for the time being).
As far as the two names in one field is concerned -- this may not be the best or most elegant way of doing it, but you could read the names into two temporary variables and then concatenate them into your name array.
I assume you are using char arrays based on an assignment, but if you don't have to use them look into strings instead.

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.