lundi 17 juillet 2017

the same result when i run the program

#include <iostream>
using namespace std;
int main()
{
  bool result;
  char text[1000];
  cin>>text;
  int len=sizeof(text);
  for(int i = 0 ;i<len; ++i)
  {
    if(text[i]=='t' && text[i+1]=='r' && text[i+2]=='u' && text[i+3]=='e') 
        result = true;
    else if(text[i]=='f' && text[i+1]=='a' && text[i+2]=='l' && text[i+3]=='s' && text[i+4]=='e')
        result = false;

  }
  for(int i = 0 ;i<len; ++i)
  {
      if(text[i]=='n' && text[i+1]=='o' && text[i+2]=='t')
          result = !result;// i think here is the problem
  }
  if(result == true)
      cout<<"true"<<endl;
  else if(result == false)
      cout<<"false"<<endl;
return 0;

the exercise: A boolean value can be either True or False. Given a string with less than 1000 characters with a number of space-separated not directives terminated by a True or False value, evaluate the boolean expression. but when i run the program the result is always true. please can you tell me where is the problem

Aucun commentaire:

Enregistrer un commentaire