What's new

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

PHC - Naethan

Forum Expert
Joined
Dec 27, 2016
Posts
3,374
Reaction
18,121
Points
2,599
Age
22
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.png


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

1695211738002.png


Eto naman yung responsive ko na code,
1695212123330.png


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
 

Attachments

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
 
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..
 
Back
Top