I would like to have the user type in a word and each letter corresponds to a number, then when the user is finished add up the total. If the the user types in abc the final output would be 6. If use the program below and type in numbers everything works fine, but for the letters the final is always 0. When it enters the loop and the user type in a, the temp variable needs to be 1, but it is staying at 0. Not sure how to get temp to equal the number value of the letter the user inputs.
#include <iostream>
usingnamespace std;
int main ()
{
int a = 1;
int b = 2;
int c = 3;
int temp;
int final;
int counter;
counter = 1;
int num;
cout << " How many letters is your word " << endl;
cin >> num;
cout << "Type in your word " << endl;
while (counter <= num)
{
cin >> temp;
final = final + temp;
counter++;
}
cout << final << endl;
return 0;
}
~
I thought this website shouldn't give the full code , but more hints (that's what I did, of course that's slower).
Also don't forget to add a little bit to your code , so that inputing "a" , 1 will be received.
Thanks for the input. I needed to use an int array since I want the letters to be variables for numbers, but I got that working. I need to get a loop and a few other things working, but suggesting the array gave me the right direction.