1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <string> //The string class
#include <sstream>
using namespace std;
string Thename;// String not Char cause we wanna hold more than 1 character
int Thenumber1;
int Thenumber2;
string Thereducednumber1;
int Thereducednumber2;
int Thereducednumber3;
//The function that converts characters of the name to numbers (reduced numbers if needed, cause the numbers in the end should be one these 0,1,2,3,4,5,6,7,8,9,11,22)
void CharactersToNumbers(){
int i = 0;
for (Thename[i]; i <= 20; i++) {
Thenumber1 = (int) Thename[i];
Thenumber2 += Thenumber1;
Thenumber1 = 0;
}
// Till here it's giving me the right value of ASCII which is 731 if I use the name "Hussain"
//But I'm trying to add the 7, 3 and 1 to the total of 11 but I'm adding the ASCII value of 731 and the actual value of the numbers
i = 0;
if (Thenumber2 != 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 11 || 12 || 22) {
ostringstream convert;
convert << Thenumber2;
Thereducednumber1 = convert.str();
for (Thereducednumber1[i]; i <= 2; i++) {
Thereducednumber2 = Thereducednumber1[i];
Thereducednumber3 += Thereducednumber2;
}
cout << "The value is: " << Thereducednumber3 << endl ;
}
else if (Thenumber2 == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 11 || 12 || 22) {
cout << "The value is: " << Thenumber2 << endl ;
}
}
//****************************** MAIN *********************************************
int main(){
cout << "Enter your name: ";
cin >> Thename;
CharactersToNumbers();
return 0;
}
|