Hey guys,


I really appreciate the effort and time you take out to help me become a better coder :!: I know I'm not the best and it takes alot of time, but, I'm having so much fun in learning this(even if they are simple programs).

I also, worked out the pseudo code WaltP gave me and turned it into this:

#include <iostream>

int main()
{
	char words[5][10];

	for (size_t i = 0; i < 5; ++i)
		std::cin >> words[i];
	std::cout << std::endl;


	for (size_t i = 0; i < 5; i++)
	{
		bool contr = true;
		for (size_t j = i+1; j < 5; j++)
		{
			if(strcmp(words[i], words[j]) == 0)
			{
				contr = false;
				break;
			}
		}
		if(contr == true)
			std::cout << words[i] << '\n';
	}
	std::cin.ignore(2);

	return 0;
}

I think it differs abit from the pseudo code he gave me, but, it works perfectly. In his pseudo code, he mentions to loop from first to last minus one, wich I "think" means this: for (size_t i = 0; i < 4; i++) . But, that doesn't seem to work for me.

Yes I would ask you to compulsorily make the change.

Normally the strcmp( ) returns -1 , 0 or 1.

My output from your program:
The ans is -32
The ans is -1
The ans is -2
using Borland 5.5

So some compilers convert the returns to -1/0/1, others just use the difference between the characters:
'A' - 'a' = 32
'c' - 'd' = -1
'b' - 'd' = -2

So definitely just use <|=|> 0

I also, worked out the pseudo code WaltP gave me and turned it into this:
<snip code>
I think it differs abit from the pseudo code he gave me, but, it works perfectly. In his pseudo code, he mentions to loop from first to last minus one, wich I "think" means this: for (size_t i = 0; i < 4; i++) . But, that doesn't seem to work for me.

Good job! Yes it differs from mine, and the main reason is you corrected a problem in my pseudo code :) My loops were a little off.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.