0

Loop Conditions (C++)

Two Questions: 1. There exists a "is not equal" condition, which is "!=". Can you create a condition that checks "is not greater/less than", since "!>" and "!<" are both illegal? 2. I have an error message in my recent code in an attempt to create a room package choice for a hotel, which states "ISO C++ forbids comparison between pointer and integer. Here is part of my code (written in Dev C++ compiler). https://code.sololearn.com/caKNM0KBqRli/#cpp

5th Apr 2019, 7:47 PM
Seij Bailey
Seij Bailey - avatar
2 Respostas
+ 4
1. Is not greater is sinonymous with less or equal so just use "<=" for "!>" and ">=" for "!<" 2. That's not how you work with string in C/C++. I don't know what type "answer" is, but you can't compare it with "a literal string", as "a liter string" turns into a pointer when you try to compare it. If you're using C-style strings use strcmp() from string.h: if (strcmp(answer, "yes") == 0 || strcmp(answer, "y") == 0) //do yes If you're using std::string: if (answer.compare("yes") == 0 || answer.compare("y") == 0) //do yes
5th Apr 2019, 7:58 PM
Vlad Serbu
Vlad Serbu - avatar