Assist in using array for word game

Hello, I'm a beginner and new to this forum. I'm really confused and stuck with a certain codes. I'm creating a memory word game and really confused on the arrays that takes word. I'm using printf, scanf, etc now because it is the one I required in comfortably use. I still don't know a lot about c++ cin, cout, etc.
Is it possible to have a program something like this?

like array = {cat,dog,rat}

/*inputted*/
cat /*\n*/
dog /*\n*/
rat /*\n*/

YOU GOT 15 POINTS!

Now, I'm really confused how to code and recognize that the output array = inputted array. I tried a similar case like this, but still not right, when i enter a word. it only recognize one word. And in addition, I dont know how to conver the cin and cout there to printf or something so i can removre the #include<iostream>.
P.S. this is just raw code and really thankful for those who can help.

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
58
59
60
61
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <time.h>
#define p printf
using namespace std;

void wait(int sec);

int main()
{
	const int a = 3;
	string word[a] = { "apple", "ball", "cat" };
	string nword[a] = { "apple", "ball", "cat" };
	string j;
	int point;
	int s = 0;
	int ctr = 0;


	p("BASIC");
	for (int i = 0; i < a; i++)
	{
		cout << nword[i] << endl;/*don't know how to convert this to C*/
	}
	int seconds = 3;
	wait(seconds);
	system("CLS");
	for (int i = 0; i < a; i++)
	{
		p("ENTER");
		cin >> j; /*don't know how to convert this to C*/
		int seconds = 5;
		wait(seconds);
		system("CLS");
		if (j == word[i])
		{
			p("==========Congratulation=========");
			p("==========You Have Score:");
			p("%d Point", i + i);

		}
		else
		{
			p("Wrong");
		}

	}
	return 0;
}

void wait(int sec)
{
	clock_t end_wait;
	end_wait = clock() + sec * CLK_TCK;

	while (clock() < end_wait) {}
}
Last edited on
Hello Russell,
If I'm not mistaken cin is like scanf, just more complicated and they're from different libraries. Scanf however, is compatible with DEV C++, codeblocks, some widely used compilers for C++. cout like printf.Only difference I've ever noticed is that one is iostream and other is cstdio (stdio.h). Anyway.
1 I'm not sure why you define printf, I've never done it with codeblocks/bloodshed dev c++.
2 I don't know about
void wait(int sec);
since I'd replace that with
void wait(int sec)
{
clock_t end_wait;
end_wait = clock() + sec * CLK_TCK;

while (clock() < end_wait) {}
}
.
Since I've never used the function clock (never had to) so I'm not sure about it.
Definitely recommend you to download Codeblocks but if you're writing C++ then remember to save files as '.cpp' without the single quotes.
Happy debugging ^~^! I hope this helped, though it's very opinionated.Lyss.
@Alyssa, thanks for the info. :)
oh and im using visual studio right now, the void wait(int sec);
is a function so I dont need to rewrite again the
1
2
3
4
5
6
7
void wait(int sec)
{
clock_t end_wait;
end_wait = clock() + sec * CLK_TCK;

while (clock() < end_wait) {}
}

in future use. Here is the tutorial i made in my progressing game, hope this clear up more in my question confusion.
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#define _CRT_SECURE_NO_WARNINGS
#define p printf
#include <stdio.h>
#include <time.h>
#include <Windows.h>

void wait(int sec);
void tuth();
void tut2();

int main(){
			tut2();
return 0;
}

void tuth()
{
	HANDLE C = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(C, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
	p("\n################################################################################");
	p("\n                                 T U T O R I A L");
}


void tut2()
{
	int seconds = 2;
	tuth();
	HANDLE C = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(C, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	wait(seconds);
	p("\n\n\n  This game will test how sharp your short-term memory is.");
	wait(seconds);
	p("\n\n  There are list of words that will appear.");
	wait(seconds);
	seconds = 6;
	p("\n\n\n\n\n        CAT               Dog              FISH              Rat");
	wait(seconds);
	seconds = 2;
	p("\n\n\n\n\n  Memorize as many words as you can in the given amount of time.");
	wait(seconds);
	p("\n\n  When the given time runs out, the list of words will disappear.");
	SetConsoleTextAttribute(C, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
	p("\n\n\n################################################################################");
	seconds = 6;
	wait(seconds);
	system("CLS");
	tuth();
	SetConsoleTextAttribute(C, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	seconds = 2;
	wait(seconds);
	p("\n\n\n  The aim of the game is to type and enter as many words as you can");
	wait(seconds);
	p("\n\n  in the list in EXACT words, each word is equal to 5 (five) points.");
	wait(seconds);
	p("\n\n  /*Sample Output*/");
	wait(seconds);
	p("\n\n  Cat/*ENTER*/       Dog/*ENTER*/         FISH/*ENTER*/         Rat/*ENTER*/");
	wait(seconds);
	p("\n\n           You got 15 Points!");
	wait(seconds);
	p("\n\n  You need to have at least 50 for Easy Mode, 65 for Normal Mode and 80 percent");
	p("\n\n  for Hard Mode of the total points to proceed to the next level.");
	wait(seconds);
	p("\n\n  There are 3 Levels per difficulty.");
	wait(seconds);
	p("\n\n");
	SetConsoleTextAttribute(C, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
	p("\n################################################################################");
}

void wait(int sec)
{
	clock_t end_wait;
	end_wait = clock() + sec * CLK_TCK;

	while (clock() < end_wait) {}
}
Topic archived. No new replies allowed.