Alright, so here's where I am now. I know I still gotta find better ways for things, but is this roughly what you meant with using the 'switch' stuff?
Code:
#include <iostream>
using namespace std;
int main()
{
// Initializing strings: Menu-selection
string title("Quiz: The basics of C++");
string section;
string section1;
string section2;
string section3;
string chapter;
string chapter1;
string chapter2;
string chapter3;
string chapter4;
string chapter5;
// Initializing strings: Error returns
string ERR("--- Sorry! Please select a number from 1-5. ---");
// Initializing Integers: Section/chapter selection
int sctn = 0;
int chptr = 0;
int x = 4;
// Defining section strings
section1 = "Introduction and Basic C++ Features";
section2 = "Pointers, Arrays and Strings";
section3 = "File IO, command line arguments and intro to classes";
// Section-selection menu
cout << title << endl;
cout << endl;
cout << "Please select a section (1-3)" << endl;
cout << "1 - " << section1 << endl;
cout << "2 - " << section2 << endl;
cout << "3 - " << section3 << endl;
cin >> sctn;
cin.ignore();
// Selecting Section
switch (sctn)
{
case 1:
section = section1;
// Defining chapters Section1 - Introduction and Basic C++ Features
chapter1 = "Intro";
chapter2 = "If Statements";
chapter3 = "Loops";
chapter4 = "Functions";
chapter5 = "Switch case";
break;
case 2:
section = section2;
// Defining chapters Section2 - Pointers, Arrays and Strings
chapter1 = "Accessing Memory with Pointers";
chapter2 = "Structures in C++";
chapter3 = "Storing data with Arrays";
chapter4 = "Character Strings in C++";
chapter5 = " ";
break;
case 3:
section = section3;
// Defining chapters Section3 - File IO, command line arguments and intro to classes
chapter1 = "File I/O";
chapter2 = "Typecasting";
chapter3 = "Classes and introduction to object-oriented programming";
chapter4 = "Inline functions";
chapter5 = "Command line arguments";
break;
default:
cout << "--- Something went wrong ---";
break;
}
cout << endl;
if ( chapter5 != " " )
{
x = 5;
}
cout << "Please select a chapter (1-" << x << ")" << endl;
cout << "1. - " << chapter1 << endl;
cout << "2. - " << chapter2 << endl;
cout << "3. - " << chapter3 << endl;
cout << "4. - " << chapter4 << endl;
if ( chapter5 != " " )
{
x = 5;
cout << "5. - " << chapter5 << endl;
}
cin >> chptr;
cin.ignore();
switch (chptr)
{
case 1:
chapter = chapter1;
break;
case 2:
chapter = chapter2;
break;
case 3:
chapter = chapter3;
break;
case 4:
chapter = chapter4;
break;
case 5:
chapter = chapter5;
break;
default:
chapter = ERR;
break;
}
cout << endl << endl;
cout << "You have selected section-number: " << sctn << endl;
cout << "The title of the section is: " << section << endl;
cout << endl << endl;
cout << "You have selected chapter-number: " << chptr << endl;
cout << "The title of the chapter is: " << chapter << endl;
}
Honestly, I gotta figure out how to do a proper dynamic numbering thingy for the selections, but I guess it does display what I want it to display at the moment.