online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
//for inputs/outputs: #include <iostream> //just a preference for convenience: using std::cout; using std::cin; using std::string; //create our function with bool datatype just for convenience: bool numbers_only(string funcsake) { //this loop compares each of the characters in the string to numbers. int i = 0; string target; do { //this is setting "target" to the target character to be "scanned": target = funcsake.substr(i, 1); //this is "scanning" the target character (or just comparing to numbers): if(target == "1"); else if(target == "2"); else if(target == "3"); else if(target == "4"); else if(target == "5"); else if(target == "6"); else if(target == "7"); else if(target == "8"); else if(target == "9"); else if(target == "0"); else return false; //we return false if even one character is not a number: //incrementing i for loop puposes: i++; } while(i < funcsake.size()); //loop continues until an unrecognized character is found, or until the string's length is reached. //if all checks, we return true: return true; } int main() { //this is simple, you most likley will understand it: cout << "Enter a number.\n"; string number; cin >> number; bool check = numbers_only(number); if(check == true) cout << "You entered a valid number.\n"; else cout << "Error: Your string contains an unrecognized character.\n"; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue