C++ help

This is the assign question



My code:

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
#include <iostream>
using namespace std ;


int main ()
{
	char w[4];
	char* wPtr=w;
	char *dictionary[4] = { "auto","bus","car","door"};
	int k;
	int i=0;

	cout << "Enter a word : " <<  endl;

	while(*dictionary[i] !='\0')
	{
		cin >> w[i] ;
		if ( *dictionary[i] == wPtr[i] )

			{
				k=1;
		    
						}
		else
		{
			k=0;
			
		}
		i++;
		
	}
	
	if (k=1)
	cout << "True" << endl;
	else
		cout << "False" << endl;


		return 0;
}


My code does not work correctly. It does not run. I do not know how to make it work.

Last edited on

My original comments would have been based on your first post but you have edited it before I answered it.

Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include <iostream>

int main()
{

	// ...

	for (int i = 0; i < 4; i++)
		if (*dictionary[i] == word) 
			located = true;

	if (located)
		std::cout << "True";
	else
		std::cout << "False";


	// ...


}
Last edited on
thank you!! it works!! i also change char word ==> string word .
Topic archived. No new replies allowed.