#Raptor/C++

7 messages · Page 1 of 1 (latest)

remote sunBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

bright tendon
#

!f

remote sunBOT
#

Hello Everyone I need help with some homework and I just need to turn this C++ code ```cpp
into a raptor flowchart.Below is my code.Help would be much appreciated !!

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

bool checkHexa(string str) {
if (str[0] != '0' || str[1] != 'x')
return false;

int n = str.length();

for (int i = 2; i < n; i++) {
char ch = str[i];

if ((ch < '0' || ch > '9') && (ch < 'A' || ch > 'F')) {
  return false;
}

}

return true;
}

int convertHexaToDecimal(string str) {
int decimal_number;

istringstream iss(str);

iss >> hex >> decimal_number;

return decimal_number;
}

string convertDecimalToHexa(int decimal_number) {
ostringstream oss;

oss << hex << decimal_number;

string result = oss.str();

for (int i = 0; i < result.length(); i++)
result[i] = toupper(result[i]);

return ("0x" + result);
}

int main() {
string hexadecimal_literal;

cout << "Please enter a hexadecimal literal ";
cin >> hexadecimal_literal;

if (checkHexa(hexadecimal_literal)) {
int decimal_number = convertHexaToDecimal(hexadecimal_literal);

string new_hexadecimal = convertDecimalToHexa(decimal_number + 1);

cout << "The next hexadecimal number is " << new_hexadecimal;

}

else {
cout << "This is not a valid hexadecimal number";
}

return 0;
}

TxBobert
bright tendon
#

@pale plinth what errors are you having

#

also check for the size of the string so if it's empty you won't have UB

remote sunBOT
#

@pale plinth

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

pale plinth
#

!solved