chore: add cprNumber program

this one was a bit of a pain working between data types
main
CrimsonTome 2023-02-06 22:18:10 +00:00 committed by Rowan Clark
parent 395d187d2a
commit 23c1032ca7
No known key found for this signature in database
GPG Key ID: F620D51904044094
2 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,7 @@
{
"files.associations": {
"iostream": "cpp",
"*.tcc": "cpp"
"*.tcc": "cpp",
"ostream": "cpp"
}
}

22
cprNumber/main.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <iostream>
#include <string>
using namespace std;
int main(){
string cprNum = "";
cin >> cprNum;
cprNum = cprNum.erase(cprNum.find('-'), 1);
int sum = 0;
int con = 0;
int mult[] = {4,3,2,7,6,5,4,3,2,1};
for (int i = 0; i< cprNum.length(); ++i){
con = cprNum[i] - '0';
sum += con * mult[i];
}
if (sum % 11 == 0){
cout << "1" << endl;
}
else{
cout << "0" << endl;
}
}