Add Variables with Predefined Values

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).

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
67
68
69
70
71
72
73
74
75
/* **** Include and Use **** */
#include <iostream>
using namespace 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;
Last edited on
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.

http://www.cplusplus.com/reference/map/map/
Hm, OK I will have to look into that. Thanks.
Topic archived. No new replies allowed.