Hi there, im trying to create a quiz program in c++.

I need to have an array within a struct as i need to store a question title, ten possible answers and the points that each answer is associated with

any help about how to go around declaring this would be appreciated!

Recommended Answers

All 8 Replies

Please post what code you have so far. Thanks :)

Structures are more related to C language than C++. Anyway you could do it loke so:

#include <string>//including the header for strings
//--------------Other-includes------------------------//
//--------------Other-structs-or-classes-------------//
typedef struct Quiz{
string qTitle;//Question title
int cAnswer;//Correct answer
int Answer;//The user's asnwer
};
//--------------The-rest-of-the-code-------------//

You could also use a vector of Answers(strings) if you want to stock all of the answers in the structure type.

Hi StuartB2,
we are here working for helping others, So plz do ur best and post here ur thoughts regard ur issue and u will find a lot of help, Thanks

Offtopic: Basteon, don't give away free help. It's not in forum policy.

SqtMe, sorry I'm new here and still not used to the forum policy...

Structures are more related to C language than C++.

That's not true, a struct is a perfectly normal thing to use in C++, just like a class. The difference between the structs and classes is that a struct defaults members to public while a class defaults to private. Yes, struct existed in C and classes didn't, but that doesn't mean structs are somehow "outdated"

Offtopic: Basteon, don't give away free help. It's not in forum policy.

Free help can be given away at all time. It's just that we discourage people to give out ready-made solutions to people who are clearly only here to get a homework freebie. Giving some code to illustrate your point is no problem at all. Don't be too harsh to our new-and-enthusiastic members ;)

On topic:

Do you perhaps mean an array of structs? That would make more sense IMO.

Yes, arrays, that's what I meant )). I gave up to arrays when I learned about vectors, since then I sometimes confuse this two notions.

Yes structures can be used in C++ but I still think that they are kind of outdated, when Stroustrup created The C++(as far as I know) he left structures just for compatibility with the older version of the language, which is C.

Yes structures can be used in C++ but I still think that they are kind of outdated, when Stroustrup created The C++(as far as I know) he left structures just for compatibility with the older version of the language, which is C.

Nope. Please re-read my previous post. Structs in C++ are exactly the same as classes with the one exception that members in structs are public by default while members in classes are private by default.

commented: Yeah, I agree. I was going to comment in their defense, but you took care of it :) +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.