Gotcha. I wasn't quite sure about the meaning/difference of constant and int when the value is visually as written the same, but figured out so far that a char would be a constant needing the single ' qotes when comparing whereas numbers don't. Correct?
Anyways, it seems to work now (i think). Here's what I made of it:
Code:
#include <iostream>
using namespace std;
int main()
{
string section("Introduction");
string title("Quiz: The basics of C++");
string chapter;
string chapter1("Intro");
string chapter2("If Statements");
string chapter3("Loops");
string chapter4("Functions");
string chapter5("Switch case");
string ERR("--- Sorry! Please select a number from 1-5. ---");
int chptr = 0;
cout << title << endl << endl;
cout << section << "..." << endl;
cout << "Please select a chapter (1-5)" << endl;
cout << "1 - " << chapter1 << endl;
cout << "2 - " << chapter2 << endl;
cout << "3 - " << chapter3 << endl;
cout << "4 - " << chapter4 << endl;
cout << "5 - " << chapter5 << endl;
cin >> chptr;
cin.ignore();
if (chptr == '0' || chptr >= '6')
{
chapter = ERR;
}
else if (chptr == 1)
{
chapter = chapter1;
}
else if (chptr == 2)
{
chapter = chapter2;
}
else if (chptr == 3)
{
chapter = chapter3;
}
else if (chptr == 4)
{
chapter = chapter4;
}
else if (chptr == 5)
{
chapter = chapter5;
}
else
{
chapter = ERR;
}
cout << "You have selected chapter-number: " << chptr << endl;
cout << endl << "The title of the chapter is: " << chapter << endl;
}
Thanks for guiding me in the right direction and not just putting up the code. I wanna learn and understand the 'why'! Awesome help! Much appreciated.