What's new

Help Pa help po to cr@ck the code using C++

JinLapuzzz

Honorary Poster
Joined
Aug 24, 2020
Posts
203
Solutions
1
Reaction
259
Points
147
Age
25
Mga ka PHC gusto ko sana patulong dito sa logic na ito.. medyo confusing siya para saken tho nagagawa ko naman siya ng tama pero may isang condition na diko makuha haha..

ito po yung task..
mag iinput ng word dapat ang word na yung ay tatanggapin lang ay (apple, tamarind, pie), kapag wala diyan ang nabanggit, magsasabi ang compiler na "wrong word"..
pero pag tama ang na input na word ganito ang mangyayari.. hahanapin niya kung saan ang may uppercase..

halimbawa:

input: pIe
output: "the 2 index letter has uppercase"

kapag..
input: blue
output : "invalid word"

kapag..
input: apple
output: "all letter are in lower case"


kapag..
input: TamarinD
output: "the 1 index has uppercase" and "8 index has uppercase"
baka pwedi ako pa code nito haha.. meron na ako kaso yung invalid word na ako problema
 
Try mo to galing kay ChatGPT


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

int main() {
    std::string words[] = {"apple", "tamarind", "pie"};

    std::cout << "Enter a word: ";
    std::string input;
    std::cin >> input;

    // convert the input string to lowercase
    std::transform(input.begin(), input.end(), input.begin(), ::tolower);

    bool found = false;
    int uppercase_index = -1;
    for (int i = 0; i < input.size(); i++) {
        if (std::isupper(input[i])) {
            found = true;
            uppercase_index = i;
            break;
        }
    }

    if (found) {
        std::cout << "The " << (uppercase_index + 1) << " index letter has uppercase." << std::endl;
    } else {
        std::cout << "No uppercase letters found." << std::endl;
    }

    return 0;
}
 
Try mo to galing kay ChatGPT


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

int main() {
    std::string words[] = {"apple", "tamarind", "pie"};

    std::cout << "Enter a word: ";
    std::string input;
    std::cin >> input;

    // convert the input string to lowercase
    std::transform(input.begin(), input.end(), input.begin(), ::tolower);

    bool found = false;
    int uppercase_index = -1;
    for (int i = 0; i < input.size(); i++) {
        if (std::isupper(input[i])) {
            found = true;
            uppercase_index = i;
            break;
        }
    }

    if (found) {
        std::cout << "The " << (uppercase_index + 1) << " index letter has uppercase." << std::endl;
    } else {
        std::cout << "No uppercase letters found." << std::endl;
    }

    return 0;
}
galing na ako kay gpt sir di niya rin masagot hahah
 
Madali lang naman yung sa invalid word? Ganito sabi ni chatgpt pero maraming puwedeng approaches dito:

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

int main()
{
  std::string input;
  std::cout << "Enter a word: ";
  std::cin >> input;

  if (input == "apple") {
    std::cout << "You entered apple." << std::endl;
  }
  else if (input == "tamarind") {
    std::cout << "You entered tamarind." << std::endl;
  }
  else if (input == "pie") {
    std::cout << "You entered pie." << std::endl;
  }
  else {
    std::cout << "Wrong word." << std::endl;
  }

  return 0;
}
 
Madali lang naman yung sa invalid word? Ganito sabi ni chatgpt pero maraming puwedeng approaches dito:

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

int main()
{
  std::string input;
  std::cout << "Enter a word: ";
  std::cin >> input;

  if (input == "apple") {
    std::cout << "You entered apple." << std::endl;
  }
  else if (input == "tamarind") {
    std::cout << "You entered tamarind." << std::endl;
  }
  else if (input == "pie") {
    std::cout << "You entered pie." << std::endl;
  }
  else {
    std::cout << "Wrong word." << std::endl;
  }

  return 0;
}
pabasa po ulit nung tanong ko po sir.. anway salamat poo
 
"meron na ako kaso yung invalid word na ako problema"

Binasa ko, hindi ba yan ang problema mo?
 
Madali lang naman yung sa invalid word? Ganito sabi ni chatgpt pero maraming puwedeng approaches dito:

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

int main()
{
  std::string input;
  std::cout << "Enter a word: ";
  std::cin >> input;

  if (input == "apple") {
    std::cout << "You entered apple." << std::endl;
  }
  else if (input == "tamarind") {
    std::cout << "You entered tamarind." << std::endl;
  }
  else if (input == "pie") {
    std::cout << "You entered pie." << std::endl;
  }
  else {
    std::cout << "Wrong word." << std::endl;
  }

  return 0;
}
mas malinis tignan if hindi if else. i check mo nlng using for loop ang array kung saan nakalagay ang mga matched keywords.
 
Code:
#include <iostream>
#include <string>
#include <algorithm>
#include <array>

int main() {
    std::array<std::string,3> words = {"apple", "tamarind", "pie"};

    std::cout << "Enter a word: ";
    std::string input;
    std::string input_lower;
    std::cin >> input;

    input_lower = input;
    // convert the input string to lowercase
    std::transform(input_lower.begin(), input_lower.end(), input_lower.begin(), ::tolower);
    if (std::find(words.begin(),words.end(),input_lower)!= words.end())
    {
        std::cout<<"Input Word : "<< input_lower<< std::endl;
    }
    else
    {
        std::cout<<"Invalid Word"<< std::endl;
    }
    return 0;
}
ito po base din sa gpt may binago lang po ako
 
Last edited:

Similar threads

Back
Top