Help with c program for class!!!

I have to write a c program for class. It is an interactive survey that asks 5 questions, supplies 4 possible responses and stores all of this in an array to output a summary report. I'm not sure where to even start. I have created some arrays: one to store the user's name when prompted( char *name[20];) One to store all of the questions to be asked( char *questions[] = {"question1","question2",....}; One to store all of the possible responses( char *responses[] = {"response1","response2",...};

It should look like this:

Do you attend class consistently?
1. Never
2. Occasionally
3. Usually
4. Frequently

Enter the number for your response: _

My instructor mentioned using function prototypes. Please help!!!!


  • Okay first off, don't use char *szText[20] typed arrays. They are dangerous! You could easily over run arrays this way. Use the STL array prototypes. I believe the header file is vector.h or just simply vector.
    It is prototyped as follows:

    vector ResponseArray;
    vector ...

    Not sure about the second one, but that should get you going on the arrays. Just search for STL, Standard Template Library.

    Now, function prototypes just means that you break down what the program does into smaller parts. This way you don't get spaghetti code like in BASIC.

    void PrintNextQuestion(int i)
    cout << QuestionArray[i] << endl;
    cin >> answer;

    And PrintPossibleResponses() would be another function prototyped in the program. Remember, a function must at least be declared before using it. So you would at least need void PrintPossibleRespsonses(int);
    before PrintNextQuestion(int i). Hope this starts you out.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion