Go Back  Xtreme Visual Basic Talk > Other Languages > Miscellaneous Languages > Type Mismatch error


Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2003, 02:32 PM
gskahlon79
Guest
 
Posts: n/a
Default Type Mismatch error


Here is my c++ program

It says Type Mismatch

Please help with this

Code:
#include <iostream.h>

#include <iomanip.h>

#include <string.h>

#define MAX_STUDENTS 50

struct students_marks
{

    int mark1;
    int mark2;
    int mark3;
    int mid_exam;
    int final_exam;
    float total_mark_percentage;

};

char *menu();

int read_data(struct students_marks, int);

void display_data(struct students_marks, int);

void process_data(struct students_marks, int);

int main()
{

    students_marks marks1[MAX_STUDENTS];

    bool done;

    char *choice;

    int count = 0;

    cout << setprecision(2)
		 << setiosflags(ios::fixed)
	  	 << setiosflags(ios::showpoint);

    while (!done)
    {

        choice = menu();

        if (stricmp(choice, "D") == 0)
        {

            process_data(marks1, count);

        }

        else if (stricmp(choice, "R") == 0)
        {

            read_data(marks1, count);

        }

        else if (stricmp(choice, "Q") == 0)
        {                                                                                                               

            done = true;

        }

    }

}

char *menu()
{

    static char my_choice[8];

    cout << "\n\nEnter your choice from :\n"
         << endl << "Type \"D\" to Display the information"
         << endl << "Type \"R\" to Read the Next Record"
         << endl << "Type \"Q\" to end the application      ";

    cin.getline(my_choice, 8);

    return my_choice;

}

int read_data(students_marks marks2[], int count)
{

    cout << "\n\nEnter the marks for the Assignment 1 : ";
    cin >> marks2[count].mark1;

    cout << "\nEnter the marks for the Assignment 2 : ";
    cin >> marks2[count].mark2;

    cout << "\nEnter the marks for the Assignment 3 : ";
    cin >> marks2[count].mark3;

    cout << "\nEnter the marks for the Mid Term Exam : ";
    cin >> marks2[count].mid_exam;

    cout << "\nEnter the marks for the Final Exam: ";
    cin >> marks2[count].final_exam;

    count++;

    cin.ignore(80, '\n');
    
    return count;

}

void display_data(students_marks marks3[], int count)
{

    cout << "\n\nMark1       Mark2       Mark3       Mid Term Test       Final Exam       % Total" << endl;

    for (int loopCounter = 0; loopCounter < count; loopCounter++)
    {

        cout << setw(10) << marks3[loopCounter].mark1 << setw(10) << marks3[loopCounter].mark2
             << setw(10) << marks3[loopCounter].mark3 << setw(10) << marks3[loopCounter].mid_exam
             << setw(10) << marks3[loopCounter].final_exam << setw(13) << marks3[loopCounter].total_mark_percentage
             << "%" << endl;
    }
    
}

void process_data(students_marks marks2[], int count)
{

    double mark1_percentage, mark2_percentage, mark3_percentage;
    double mid_exam_percentage, final_exam_percentage;
    double weightage_of_mark1, weightage_of_mark2, weightage_of_mark3;
    double weightage_of_mid_exam, weightage_of_final_exam;

    for (int loopCounter = 0; loopCounter < count; loopCounter++)
    {

        mark1_percentage = (marks2[loopCounter].mark1 / 100) * 100;
        mark2_percentage = (marks2[loopCounter].mark2 / 200) * 100;
        mark3_percentage = (marks2[loopCounter].mark3 / 300) * 100;

        mid_exam_percentage = (marks2[loopCounter].mid_exam / 500) * 100;

        final_exam_percentage = (marks2[loopCounter].final_exam / 500) * 100;

        weightage_of_mark1 = (5 / 100) * mark1_percentage;
        weightage_of_mark2 = (10 / 100) * mark2_percentage;
        weightage_of_mark3 = (15 / 100) * mark3_percentage;

        weightage_of_mid_exam = (25 / 100) * mid_exam_percentage;
        weightage_of_final_exam = (45 / 100) * mid_exam_percentage;

        marks2[loopCounter].total_mark_percentage = weightage_of_mark1 + weightage_of_mark2 + weightage_of_mark3 + weightage_of_mid_exam + weightage_of_mid_exam;

    }

    display_data(marks2, count);

}
Edit: Added code tags

Last edited by Orbity; 02-15-2003 at 03:28 PM.
Reply With Quote
  #2  
Old 02-15-2003, 04:12 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Two problems I see which should get you started. After doing these things I was able to get your program to run on Visual C++ 6 and Dev-C++ 4, but there are still some logic errors you will need to sort through.

At any rate, your function declerations which have a parameter of type "students_marks" are declared wrong. Remove the struct keyword and add a name for the parameter, in the following I have simply used the names you were already using in the actual function itself.
Code:
//These are what you had
int read_data(struct students_marks, int);
void display_data(struct students_marks, int);
void process_data(struct students_marks, int);
Code:
// should be like this
int read_data(students_marks marks2[], int);
void display_data(students_marks marks3[], int);
void process_data(students_marks marks3[], int);
Then another thing is your loop in main isn't actually being executed, to make sure it will execute change your decleration of the boolean variable:
Code:
...
bool done;
...
to
Code:
...
bool done = false;
...
Orbity
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #3  
Old 02-17-2003, 08:22 AM
gskahlon79
Guest
 
Posts: n/a
Default I am Almost there

Hi,

I am almost there.

It compiles successfully.

But in the process_data function, variables all remain zero. I am also dsiplaying there values. I mean variables do not contain any values.

Plese run the program and have a look at the process_data function.

Please help.

Here is the output

<-------------------------------------------------------------------------------->

Enter your choice from :

Type "D" to Display the information
Type "R" to Read the Next Record
Type "Q" to end the application r


Enter the marks for the Assignment 1 : 23

Enter the marks for the Assignment 2 : 123

Enter the marks for the Assignment 3 : 234

Enter the marks for the Mid Term Exam : 456

Enter the marks for the Final Exam: 456


Enter your choice from :

Type "D" to Display the information
Type "R" to Read the Next Record
Type "Q" to end the application d

0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00

Mark1 Mark2 Mark3 Mid Term Test Final Exam % Total

34 123 245 456 456 0.00%

23 123 234 456 456 0.00%



Enter your choice from :

Type "D" to Display the information
Type "R" to Read the Next Record
Type "Q" to end the application

<-------------------------------------------------------------------------------->

Here is my program code

<-------------------------------------------------------------------------------->

Code:
#include <iostream.h>

#include <iomanip.h>

#include <string.h>

#define MAX_STUDENTS 50

struct students_marks
{

    int mark1;
    int mark2;
    int mark3;
    int mid_exam;
    int final_exam;
    float total_mark_percentage;

};

char *menu();

int read_data(students_marks [], int);

void display_data(students_marks [], int);

void process_data(students_marks [], int);

void main()
{

    students_marks marks1[MAX_STUDENTS];

    bool done = false;

    char *choice;

    int count = 0;

    cout << setprecision(2)
		 << setiosflags(ios::fixed)
	  	 << setiosflags(ios::showpoint);

    while (!done)
    {

        choice = menu();

        if (stricmp(choice, "D") == 0)
        {

            process_data(marks1, count);

        }

        else if (stricmp(choice, "R") == 0)
        {

            count = read_data(marks1, count);

        }

        else if (stricmp(choice, "Q") == 0)
        {

            done = true;

        }

    }

}

char *menu()
{

    static char my_choice[8];

    cout << "\n\nEnter your choice from :\n"
         << endl << "Type \"D\" to Display the information"
         << endl << "Type \"R\" to Read the Next Record"
         << endl << "Type \"Q\" to end the application      ";

    cin.getline(my_choice, 8);

    return my_choice;

}

int read_data(students_marks marks2[], int count)
{

    cout << "\n\nEnter the marks for the Assignment 1 : ";
    cin >> marks2[count].mark1;

    cout << "\nEnter the marks for the Assignment 2 : ";
    cin >> marks2[count].mark2;

    cout << "\nEnter the marks for the Assignment 3 : ";
    cin >> marks2[count].mark3;

    cout << "\nEnter the marks for the Mid Term Exam : ";
    cin >> marks2[count].mid_exam;

    cout << "\nEnter the marks for the Final Exam: ";
    cin >> marks2[count].final_exam;

    count++;

    cin.ignore(80, '\n');

    return count;

}

void process_data(students_marks marks2[], int count)
{

    double mark1_percentage, mark2_percentage, mark3_percentage;
    double mid_exam_percentage, final_exam_percentage;
    double weightage_of_mark1, weightage_of_mark2, weightage_of_mark3;
    double weightage_of_mid_exam, weightage_of_final_exam;

    for (int loopCounter = 0; loopCounter < count; loopCounter++)
    {

        mark1_percentage = (marks2[loopCounter].mark1 / 100) * 100;
        cout << endl << mark1_percentage;

        mark2_percentage = (marks2[loopCounter].mark2 / 200) * 100;
        cout << endl << mark2_percentage;

        mark3_percentage = (marks2[loopCounter].mark3 / 300) * 100;
        cout << endl << mark3_percentage;

        mid_exam_percentage = (marks2[loopCounter].mid_exam / 500) * 100;
        cout << endl << mid_exam_percentage;

        final_exam_percentage = (marks2[loopCounter].final_exam / 500) * 100;
        cout << endl << final_exam_percentage;

        weightage_of_mark1 = (5 / 100) * mark1_percentage;
        cout << endl << weightage_of_mark1;

        weightage_of_mark2 = (10 / 100) * mark2_percentage;
        cout << endl << weightage_of_mark2;

        weightage_of_mark3 = (15 / 100) * mark3_percentage;
        cout << endl << weightage_of_mark3;

        weightage_of_mid_exam = (25 / 100) * mid_exam_percentage;
        cout << endl << weightage_of_mid_exam;

        weightage_of_final_exam = (45 / 100) * final_exam_percentage;
        cout << endl << weightage_of_final_exam;

        marks2[loopCounter].total_mark_percentage = weightage_of_mark1 + weightage_of_mark2 + weightage_of_mark3 + weightage_of_mid_exam + weightage_of_final_exam;
        cout << endl << marks2[loopCounter].total_mark_percentage;

    }

    display_data(marks2, count);

}

void display_data(students_marks marks3[], int count)
{

    cout << "\n\nMark1       Mark2       Mark3       Mid Term Test       Final Exam       % Total" << endl;

    for (int loopCounter = 0; loopCounter < count; loopCounter++)
    {

        cout << setw(3) << marks3[loopCounter].mark1 << setw(13) << marks3[loopCounter].mark2
             << setw(12) << marks3[loopCounter].mark3 << setw(15) << marks3[loopCounter].mid_exam
             << setw(19) << marks3[loopCounter].final_exam << setw(17) << marks3[loopCounter].total_mark_percentage
             << "%" << endl;
    }

}
<-------------------------------------------------------------------------------->

Edit: Please use the [code][/code] tags when posting code

Last edited by Squirm; 02-20-2003 at 07:23 AM.
Reply With Quote
  #4  
Old 02-18-2003, 07:59 PM
Jakeman
Guest
 
Posts: n/a
Default

I think it looks like you have a problem in your read_data function, or actually there isn't anything wrong with the function itself, it is working right but not doing what you think.

When students_marks marks2[] is created when the function is called, you read the data into it, then when the funciton is done, students_marks marks2[] is then destroyed, destroying all your entered data.

I think you need to pass a reference to students_marks rather than students_marks.

I haven't done any c++ in couple of years so I may be wrong, but check it out.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->