So I am trying to write a program that lets the user enter 3 letters. I assigned values to upper and lower case letters as well as % and &. Now I need to know how to take 3 letters from the user, and print their values (which by the way the user does not know). Here is what I have so far (not much).
/* **** Include and Use **** */
#include <iostream>
usingnamespace std;
/* **** Variables **** */
a = 1.0;
b = 1.1;
c = 1.2;
d = 1.3;
e = 1.4;
f = 1.5;
g = 2.0;
h = 2.1;
i = 2.2;
j = 2.3;
k = 2.4;
l = 2.5;
m = 3.0;
n = 3.1;
o = 3.2;
p = 3.3;
q = 3.4;
r = 3.5;
s = 4.0;
t = 4.1;
u = 4.2;
v = 4.3;
w = 4.4;
x = 4.5;
y = 5.0;
z = 5.1;
A = 5.2;
B = 5.3;
C = 5.4;
D = 5.5;
E = 6.0;
F = 6.1;
G = 6.2;
H = 6.3;
I = 6.4;
J = 6.5;
K = 7.0;
L = 7.1;
M = 7.2;
N = 7.3;
O = 7.4;
P = 7.5;
Q = 8.0;
R = 8.1;
S = 8.2;
T = 8.3;
U = 8.4;
V = 8.5;
W = 9.0;
X = 9.1;
Y = 9.2;
Z = 9.3;
& = 9.4;
% = 9.5;
/* **** Main Function **** */
int main()
{
cout << " -Enter 3 Letters-\n " << "-These can be UPPER or LOWER case-\n" << "-These can also be & or %-\n" << endl;
Yes I know how to fetch input. However, I do not know how to take 3 Letters and print each ones value. I have this:
1 2 3 4 5 6
int main()
{
cout << " -Enter 3 Letters-\n " << "-These can be UPPER or LOWER case-\n" << "-These can also be & or %-\n" << endl;
char letter;
cin >> letter
}
The names of your variables do not exist beyond compilation. See that variable you named "a"? With the value 1.0? "a" does not exist after compilation.
You need a data structure known as a "map". This data structure will store variables, with names.
Create a map of float values. Add the values you want to the map, with the string (for example, "a") as the label (known as a "key"). Then, you can fetch the numbers from the map using the string the user inputs.