C++/arrays and functions

Advertisement

Expert: Joseph Moore - 11/14/2009

QuestionHello, i have an assignment due for my programming class. The assignments was to write a program using 2 arrays, one to key in the students answers to a test, and one the held the correct answers to the test. the next step is to display how many questions the student got right and indicate if they passed or not. passing is 15 correct answers. this last part has to be done with a function. i am not sure how to write a function that will compare the answers in 2 arrays? could you please help ? any help would be greatly appreciated
thank you
chris

AnswerHi, Christopher.

There are several ways to write a function to compare data in two arrays. The best method is probably to pass each array in as a pointer and a size for the arrays, something like:

int compareAnswers(int *_array1, int* _array2, int _arraySize)

The body of the function would need to loop from zero to _arraySize and compare the data in each array, something like:

Joseph Moore

Expertise

I've been programming in one form or another since my brother taught me BASIC when I was 6. I've been programing professionally since I was 20, first web development with HTML, JS, DHTML, CSS, etc., then I became a video game developer, writing code in C, C++, C#, SQL, assembly, and various scripting languages. I've even written my own scripting languages, custom designed for the games I was making. I also dabble in Java, PHP, and Perl. I've worked on pretty much every aspect of game development, including graphics, audio, gameplay, tool, UI, input, animation, and physics.

Experience

I've been writing C++ code for 12 years, both on my own in my spare time and professionally.

OrganizationsIGDA

Education/CredentialsBachelor of Science in Game Design and Development, Full Sail University, Winter Park, FL

Awards and HonorsSalutatorian and Advanced Achiever Awards at Full Sail; Independent Games Festival Student Showcase winner, 2004; Featured article on Gamasutra about an experimental game developed in 2004