Results 1 to 7 of 7

Thread: Help me before i explode Please! C++

  1. #1
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts

    Help me before i explode Please! C++

    Right i am trying to make a program using C++ which is proving to be the hardest thing i have ever done in my life. I have been trying for hours now looking at examples etc and nothing wants to work at all. I was wondering if someone can help me out a bit here before i smash my key board over my head.

    Right i want to make a program that

    1. Displays a welcome message and asks if the user wants to enter 5 results and if not then exit.

    2. Then if they say yes enter 5 names, one set of results and another set of results.

    3. For each person the 2 results should add together and display the grade.

    4. This should loop 5 times and at the end all details should be displayed with final results.

    5. The program should then return to asking them if they want to enter another lot of 5.

    I have been trying to get this to work for ages now. I have set the cases up and the global variables and everything is just set up wrong. I don’t think i have used Borland C++ in about a year so very rusty.

    Anyone out there who can lend me a hand would be much appreciated.

  2. #2
    Senior Member
    Join Date
    Jul 2003
    Location
    Pit, stone.
    Posts
    643
    Thanks
    0
    Thanked
    0 times in 0 posts
    Why not post what you have done so all the gurus can have a look and see where you are going wrong?
    Well Hello!

  3. #3
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts
    Yea would help sorry

    #include <iostream.h> //Processor Instructions
    #include <conio.h>
    #include <ctype.h>
    #include <stdio.h>
    #include <string.h>


    char grade[5][14]; //Declaring of Variables
    void welcome (void);
    char batch (void);
    void getGrade(int mark, int total);

    main()
    {
    char answer;
    welcome();

    answer = batch();
    while (answer=='y'||answer=='Y')
    {
    int totalMark[5], i;
    for (i=0; i<5; i++)

    {
    cout<<"\nTotal mark for Assignments "<<(i+1)<<": ";
    cin>>totalMark[i];
    cout<<"Total Mark: "<<totalMark[i]<<"\t";
    getGrade(i, totalMark[i]);
    cout<<"Grade: "<< grade[i];
    }

    cout<<"\n\nSUMMARY OF GRADES:-\n\n";
    for (i=0; i<5; i++)
    cout<<"Total Mark: "<<totalMark[i]<<"\tGrade: "<<grade[i]<<endl;

    clrscr();
    gotoxy(5, 2);
    cout<<"Thank you for using this program";
    getch ();
    return 0 ;
    }
    }

    void welcome(void)
    {
    clrscr();
    gotoxy(5, 2);
    cout <<"Welcome to the student grading system\n\n";
    gotoxy(5, 4);
    cout<<"Please press Enter when ready \n";
    gotoxy(5, 6);
    getch();
    }

    char batch(void)
    {
    char key;
    clrscr();
    gotoxy(5, 2);
    cout<<"Do you want to process a batch of 5 students?";
    gotoxy(5, 4);
    cout<<"Enter Y Or N \n";
    gotoxy(5, 6);
    cin>>key;
    return key;
    }



    void getGrade(int mark, int total) //Retrive and Validatethe user's mark
    {
    switch (total)
    {

    case 1: strcpy(grade[mark], "Merit");
    break;
    case 2: strcpy(grade[mark], "Pass");
    break;
    case 3: strcpy(grade[mark], "Fail");
    break;
    default: strcpy(grade[mark], "Invalid Grade");
    }

    return;
    }

    This is how far i have got. It works but i need to add the names to it also i need it to display at the end all the grade/results at the end and return to the start to see if the user wishes to repeat the process.

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    This is a program I wrote a long time ago in C. It's not a solution but it should prove fairly helpful.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    typedef struct {
    					char surname[15];
    					char forename[15];
    					char telephone[15];
    					}PERSON;
    
    PERSON person;
    
    void main(void)
    {
    	void write_names(void), read_names(void);
    	char reply;
    
    	do
    	{
    		clrscr();
    		printf("\t\t\tElectronic Address Book\n\n");
    		printf("1. Add a name\n");
    		printf("2. List all names\n");
    		printf("3. Quit\n");
    		reply = getchar();
    		fflush(stdin);
    		switch(reply)
    		{
    			case '1' : write_names();
    							break;
    			case '2' : read_names();
    		}
    	}
    	while (reply != '3');
    }
    
    void write_names(void)
    {
    	FILE *fp;
    
    	if((fp = fopen("names.dat","ab")) == NULL)
    		printf("Unable to open file!");
    	else
    	{
    		printf("Please enter surname	: ");
    		gets(person.surname);
    		printf("Please enter forname	: ");
    		gets(person.forename);
    		printf("Please enter telephone number	: ");
    		gets(person.telephone);
    		fwrite(&person,sizeof(PERSON),1,fp);
    		fclose(fp);
    	}
    }
    
    void read_names(void)
    {
    	FILE *fp;
    	int result;
    
    	clrscr();
    	if((fp = fopen("names.dat","rb")) == NULL)
    		printf("Unable to find file");
    	else
    	{
    		while(!feof(fp))
    		{
    			result = fread(&person,sizeof(PERSON),1,fp);
    			if (result != NULL)
    				printf("%s %s Telephone : %s\n",person.forename,person.surname,person.telephone);
    		}
    		fclose(fp);
    		printf("\n\nPress ENTER to continue");
    		getchar();
    		fflush(stdin);
    	}
    }
    To err is human. To really foul things up ... you need a computer.

  5. #5
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Or even:

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define MAX_STUD  2
    #define MAX_MARKS 3
    
    typedef struct	{
    						char forename[15];
                      char surname[15];
                      int marks[MAX_MARKS];
    					}	STUDENT;
    
    STUDENT student[MAX_STUD];
    
    void main(void)
    {
    	void get_marks(void), print_fails(void);
    
       get_marks();
       print_fails();
    }
    
    void get_marks(void)
    {
    	int loop, loop2, mark, result;
       char temp[25];
    
       for (loop = 0;loop < MAX_STUD;loop++)
       {
       	clrscr();
          printf("\t\t\tStudents Marks Analysis\n\n");
          printf("\nPlease enter students forename: ");
          gets(student[loop].forename);
          printf("\nPlease enter students lastname: ");
          gets(student[loop].surname);
          for (loop2 = 0;loop2 < MAX_MARKS;loop2++)
          {
          	do
             {
             	printf("\nPlease enter mark number %d:",loop2+1);
                gets(temp);
                result = sscanf(temp,"%d",&mark);
                if (result != 1 && (mark < 0 || mark > 100))
                	printf("\aIllegal Result! \nPlease re-enter: ");
             }
             while(result != 1 && (mark < 0 || mark > 100));
             student[loop].marks[loop2] = mark;
          }
       }
    }
    
    void print_fails(void)
    {
    	int loop, loop2, average;
    
       clrscr();
       printf("\t\t\tPrinting Failures ...... \n");
       for (loop = 0;loop < MAX_STUD;loop++)
       {
       	average = 0;
          for (loop2 = 0;loop2 < MAX_MARKS;loop2++)
          	average += student[loop].marks[loop2];
          average /= MAX_MARKS;
          if (average < 40)
          	printf("\n %s %s Average mark %d ",student[loop].forename,student[loop].surname,average);
       }
    My mistake.
    To err is human. To really foul things up ... you need a computer.

  6. #6
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts
    Cheers for that yamangman but i am not glued up in C i just about get my head around C++ i know the syntax is the same but it is going over my head. Cheers for the help anyway pal.

  7. #7
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    So, what exactly is the problem? You say the code you provided functions correctly. Looking at it like a database, you want a forename, surname, grade1, grade 2 for 5 records.

    You should use a structure as in the examples above, with character strings for forename/surname, integers for the others. You should be able to see how MAX_STUD in the above example is used to limit the number of records to 2, in your case you would want that at 5.

    The above prints the 'failed' marks. You just need to add the two values together for each iteration of the loop for total and then use your case to print distinction etc.

    The only thing you should have to change in my program (at a quick glance) to 'make it C++' is printf and gets to cout/cin and main with no return type.
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. my head is about to explode :(
    By MuzTee in forum PC Hardware and Components
    Replies: 16
    Last Post: 01-12-2004, 10:24 AM
  2. Please help me!!! Before I explode!!!
    By NeilI in forum Software
    Replies: 4
    Last Post: 25-09-2004, 09:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •