⚙️ C & C++ Ask lang about 'string' comparing on C++, newbie question

PHC - Naethan

Forum Expert
Gandang gabi mga ka PHC ask ko lng about sa 'String comparing' bat ayaw gumana kahit mukhang tama naman logic ko, pa check nalang mga mamaw..

Eto yung bool para sa pag check ng 'numbers'

1695211788373.webp


Eto yung inside code, anong mali at tama dito sa dalawang code

1695211738002.webp


Eto naman yung responsive ko na code,
1695212123330.webp


Di ko maunawan, bakit ayaw gumana nang una kong logic compared dito sa fixed, paki enlighten po ako mga master thanks in adv :):coffee:

PHC - Naethan
 
Hi Naethan! Sure, I'd be happy to help you with your string comparing logic.

To compare two strings in C++, you can use the compare() function from the <string> library. This function returns an integer value indicating the relationship between the two strings. Here's an example:

C++:
#include <iostream>
#include <string>

int main() {
    std::string str1 = "apple";
    std::string str2 = "banana";

    int result = str1.compare(str2);

    if (result == 0) {
        std::cout << "The strings are equal." << std::endl;
    } else if (result < 0) {
        std::cout << "str1 is less than str2." << std::endl;
    } else {
        std::cout << "str1 is greater than str2." << std::endl;
    }

    return 0;
}

In this example, we compare two strings (str1 and str2). The compare() function returns 0 if the strings are equal, a negative value if str1 is less than str2, and a positive value if str1 is greater than str2.

If you can provide more details about your specific logic and what you're trying to achieve, I can help you further.
 
lagay mo sa online notepad yung code para mabailis ma trace, ang hirap pag image
Oks na na fix ko na, Dpat pala nasa taas muna yung mga true, then else if 'numbers' condition muna bago yung '!= yesD' kase yung numbers is still not equal parin kay yesD, kaya nag tataka ako bat ayaw lumabas nang loob non hahaha.. true pala muna bago false sa mga gantong case..
 

About this Thread

  • 3
    Replies
  • 961
    Views
  • 2
    Participants
Last reply from:
PHC - Naethan

Trending Topics

Online now

Members online
558
Guests online
939
Total visitors
1,497

Forum statistics

Threads
2,273,602
Posts
28,950,566
Members
1,235,856
Latest member
sentro2354
Back
Top