quiz game

Apr 21, 2021 at 4:32pm
j
Last edited on Apr 22, 2021 at 4:36pm
Apr 21, 2021 at 5:21pm
As a starter which will display the numeric codes for the word, consider:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cctype>
using namespace std;

int main()
{
	srand(static_cast<unsigned int>(time(nullptr)));

	cout << "Richard Osman's house of Games: This round is in code.\n\n\n";
	cout << "The objective of this round is to unscramble the coded word, you will be given the category as the clue and you have to type out what you belive the answer to be, with a capital letter\n\n";

	string Name;

	cout << "But First, Enter your first name: ";
	getline(cin, Name);

	cout << "Welcome contestant " << Name << ". Are you ready to begin the quiz? ";
	cout << "please type Yes or No (case sensitive): ";

	string respond;

	cin >> respond;
	if (respond == "Yes")
		cout << "\nGood luck!";
	else {
		cout << "Maybe next time!\n";
		return 0;
	}

	cout << "The first category is...\n";
	cout << "Premier League Football Teams!\n";

	vector<string> lines;
	ifstream file("Premier_League_Teams.txt");

	if (!file)
		return (std::cout << "Cannot open file\n"), 1;

	for (string line; getline(file, line); lines.push_back(line));

	const auto random_number {rand() % lines.size()};
	const auto word {lines[random_number]};
	const auto codes {new int[word.length()] {}};

	for (size_t i = 0; i < word.length(); ++i)
		if (isalpha(static_cast<unsigned char>(word[i]))) {
			codes[i] = std::tolower(static_cast<unsigned char>(word[i])) - 'a' + 1;
			cout << codes[i] << ' ';
		}

	delete[] codes;
}


Apr 21, 2021 at 5:26pm
.
Last edited on Apr 22, 2021 at 4:37pm
Apr 21, 2021 at 8:50pm
.
Last edited on Apr 22, 2021 at 4:37pm
Apr 22, 2021 at 10:33am
Before you get into the specifics of coding, you really should first design the program - not code 'on the hoof'. A major part of programming is design - and not writing code!

IMO you should first take a step back, produce a program design and then start to code from the design. Code in small parts and get each part working/tested before processing to the next part.
Last edited on Apr 22, 2021 at 10:34am
Apr 23, 2021 at 7:51pm
What is this? I don't understand...

@JackladYT, are you editing your posts and deleting their content after you get your answers?

If so, please don't. It does not help other people who might read this to get help on something. And it doesn't make sense for people who want to help you with a different solution.
Apr 24, 2021 at 9:45am
Last edited on Apr 24, 2021 at 11:35am
Topic archived. No new replies allowed.