I am attempting to create a simple Gematria Calculator.
Basically, I will assign each letter of the English alpha-beit, have the user enter a string such as a name or random word, and have the code add up the value of each individual letter and return the sum of all letters.
For example; Saturnia, 618
Sadly my C++ skills are very limited, and I need to make this as soon as possible. I am not advanced enough to write such code, so could anyone please lend me a hand? Danke.
This doesn't sound like a homework question, so here's some code...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string str;// for user input
cout << "Enter a string: "; cin >> str;
int sum = 0;// for summing the letter values.
for(size_t i=0; i<str.size(); ++i)// loop through the string 1 char at a time
sum += (int)str[i];// using the ascii value for each letter
cout << "sum = " << sum << endl;
return 0;
}
Here's the output for your example:
Enter a string: Saturnia
sum = 839
Your example assigns sum = 618 though, so I don't know what you are assigning as a value to each letter. Hopefully you can adapt the above code to work.
And so on... Each letter increases by 6, so each letter has a specific value. For example, the letter X has the value of 144, and that value is obtained by multiplying 24 x 6, while the letter S is 114, N is 84, etc. It is based on an old language I used to speak.
For example, the word CRISTOS would be, 618. An array of sorts must be conjured. Unfortunately I have not had the time to study this programming language before, and I'm afraid I need to whip this one out before Halloween.
OK. If you want the sum to be case insensitive (so that Saturnia has the same value as SATURNIA for example) then substitute this for line 12 in my code above: sum += 6*( 1 + toupper(str[i]) - 'A' );
Be sure to #include<cctype> at the top of the file for the toupper() to work.
If you want the result to be case sensitive (eg Saturnia = 1962 but SATURNIA = 618) then use this for line 12 instead: sum += 6*( 1 + str[i] - 'A' );
If the word is entered all caps then either way the output will be:
Enter a string: SATURNIA
sum = 618
and:
Enter a string: CRISTOS
sum = 618
Was it intended that both words have the same value? It so happens that they do!
BTW: Who's Illuminat?
Saturnia and Cristos are names for the same image/archetype.
Illuminat, is my way of making my presence known. It would be the same as when people say, Hello.
Eternally yours in L.V.X
Saturnia Regna, the Morning Star
Post Scriptum
I thank you ever so much for all your help. I shall attempt to modify the source code you've provided me with in an attempt to make it loop back to the beginning once it is done. This will allow my pupils to keep toying with it. Much like the real world, if I may say.
Expect to hear from me again if I somehow manage to fail.