Results 1 to 3 of 3

Thread: C++ Help

  1. #1
    Registered+
    Join Date
    Dec 2004
    Posts
    49
    Thanks
    0
    Thanked
    0 times in 0 posts

    C++ Help

    ive wrote this program which inputs a score and gives a grade compared to the score,
    well im half way there
    but it wont run it asks me to put a semi colon next to a function which isnt correct
    Could any1 help pls

    here u go

    #include <iostream.h>
    #include <conio.h>
    #include <ctype.h>
    #include <stdio.h>
    #include <string.h> //for strcpy library function
    char Grade[5][14];
    //function prototype
    void welcomeScreen (void);
    char batchScreen (void);
    void getGrade(int mark, int total);

    main()
    {
    char answer;
    welcomeScreen();

    answer = batchScreen();
    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";
    //call 'getGrade' passing in totalMark number and grade - 2 input parameters
    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 ;
    }


    //function definition
    void welcomeScreen (void)
    {
    clrscr();
    gotoxy(5, 2);
    cout <<"Welcome to the student grading system\n\n";
    gotoxy(5, 4);
    cout<<"Press any key when you are ready \n";
    gotoxy(5, 6);
    getch();
    }

    char batchScreen (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;
    }

    //get and validate user's mark


    void getGrade(int mark, int total)
    {
    switch (total)
    {
    //Note the use of the 'strcpy' library function used to assign a new value to
    //a string variable - cannot use the assignment operator '='
    //to assign a new value to such a variable

    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;
    };
    }

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    On what line does the error occur? And you can paste you're code inside code tags which will persist any indentation.

    Edit:

    I see it, you appear to be missing a final 'end' brace in main. Remove the brace at the end with the semicolon and put one at the end of main.
    Last edited by yamangman; 20-12-2004 at 02:43 PM.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Registered+
    Join Date
    Dec 2004
    Posts
    49
    Thanks
    0
    Thanked
    0 times in 0 posts

    thanks

    thanks m8,
    Simple things that make a big difference!
    .....
    And it works!
    Ta

Thread Information

Users Browsing this Thread

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

Posting Permissions

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