how to use characters in an "If" condition

-5

hello someone could tell me how to make this condition condition (Day == "Wednesday") is a program that discounts movie tickets if it is Wednesday but it does not work.

    
asked by efren ortega 16.04.2018 в 06:36
source

3 answers

2

If you use C-style character arrays you have to use a function that compares both arrays and returns the result of the comparison ... the character strings can not be directly compared but you can verify the result of a function:

char Dia[20] = /* ... */
if (strcmp(Dia, "miercoles") == 0)
{
  // ...
}

Although since you are in C ++ you can use std::string . This class has its own comparison operator, with which you can write in a natural way:

std::string Dia = "miercoles";
if( Dia == "miercoles" )
{
  // ...
}
    
answered by 16.04.2018 в 08:51
1

To compare 2 text strings in c the strcmp

is used

You would use something like this:

if (strcmp(Dia, "miercoles") == 0) { /* descuenta las entradas de cine */ }

The function returns 0 when the 2 strings are equal

    
answered by 16.04.2018 в 07:35
-1

To compare two strings in c ++ you must:

string a = "A";
string a = "B";

if(!a.compare(b))
   // Son iguales
else
   // No lo son
    
answered by 16.04.2018 в 08:42