Last active
December 18, 2018 15:11
-
-
Save artulloss/54f7de7f07098e7e1371d40cdba8245a to your computer and use it in GitHub Desktop.
A c++ factorial script I wrote in like 5 minutes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
unsigned long factoral(const unsigned long i) { | |
if(i == 1) | |
return 1; | |
return i * factoral(i - 1); | |
} | |
int main() | |
{ | |
while(true) { | |
std::cout << "Enter a number to find the factoral, or press q to quit: "; | |
std::string string; | |
getline(std::cin, string); | |
bool onlyDigits = true; | |
for(char ch : string) { | |
if(ch == 'q' || ch == 'Q') | |
return 0; | |
if(onlyDigits == true && !isdigit(ch)) | |
onlyDigits = false; | |
} | |
if(onlyDigits){ | |
std::cout << factoral(stoi(string)) << "\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment