If Statement?

I have been trying different things, but I cant get this if statement to work.
Declarations
1
2
3
4
5
6
7
8
#include <iostream>

using namespace std;

char name[150]     = "none";
char problem[3000] = "none";
char timeDate[200] = "none";
char solution[50]  = "none";

If statement
1
2
3
4
5
6
7
8
9
{
	cout << "Type internet to fix your internet connection: ";
	cin.getline(solution,50);

	if ((solution == "internet") || (solution == "Internet") || (solution == "INTERNET")){
		system("ipconfig /flushdns");
		system("ipconfig /release");
		system("ipconfig /renew");
}

When I type internet,Internet,or INTERNET, it will not run the commands in the if statement. If i create an else statement and cout the solution value it says internet, yet when I type internet the if statement doesnt run. Could you tell me what is wrong with the code?
if ((solution == "internet") || (solution == "Internet") || (solution == "INTERNET"))

You can't compare string literals like this. You need to use something like this:

if(strcmp(solution,"internet") || strcmp(solution,"Internet") || strcmp(solution,"INTERNET"))

Also, instead of checking EVERY possible caps combination, why don't you try making a function that converts the inputted string to all caps or all lowercase?
Last edited on
@PiMaster
Reference wrote:
Return Value

Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.


*http://www.cplusplus.com/reference/clibrary/cstring/strcmp/

So, comparing two C-strings for equality:
1
2
3
if ( !strcmp("str1","str1") ) {}
//or
if ( strcmp("str1","str1") == 0 ) {}


@OP
Use std::string. It has overloaded == operator.
http://www.cplusplus.com/reference/string/string/
Whoops, thanks for pointing that out, R0mai =P
+1 for using std::string.
Thanks, that fixed my first problem. For some reason though, now whenever I enter a value for the variable "solution",no matter what the value is it always runs both if statements anyway.
1
2
3
4
5
6
7
8
9
10
11
if(strcmp(solution,"internet") || strcmp(solution,"Internet") || strcmp(solution,"INTERNET")){
		system("ipconfig /flushdns");
		system("ipconfig /release");
		system("ipconfig /renew");
	}
	else {}

	if(strcmp(solution,"user") || strcmp(solution,"User") || strcmp(solution,"USER")){
		system("whoami");
	}
	else {}
Nevermind, R0mai's code solved the problem.
Topic archived. No new replies allowed.