Assigning array values.

I am attempting to write a trigonometry program in which 6 possible values can be put into formulas (depending on which variables are known, different formulas will be used.

I first declared 2 string arrays.

1
2
string invalue[5];
string tvalue[2];


One array for the six possible values, and other for the 3 true values.

1
2
3
4
5
6
7
8
			
cout << "a: ";
getline(cin, invalue[0]);
		if (invalue[0] != "n" && invalue[0] != "N")
		{
		tvalue[i] = invalue[0];
		i++;
		}


I have previously told the user that if they do not know the value, to input "n". I also declared i as a variable that equals 0 previously.

I repeat that line of code 5 more times, increasing invalue[0] to invalue[1], so on and so forth.

Here is my entire code for your picking pleasure. ( I know I use system calls, I don't plan to make a living from C++)

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
	string introreq;
    string invalue[5];
	string tvalue[2];
	int i = 0;
	cout << "Welcome to the law of Sines / Cosines program.";
	cout << '\n' << "Would you like an introduction? (yes/no) : ";
	getline (cin, introreq);
	
		if (introreq == "yes")
		{
			system("CLS");
			cout << "For the purpose of working with triangles, there will be 6 variables;" << '\n' << "a, b, c, A, B, C";
			cout << '\n' << '\n' << "All uppercase letters are angles, and all lowercase letters are sides.";
			cout << '\n' << "Corresponding letters are opposite eachothers." << '\n' << "For example angle A is opposite side a";
			cout << '\n' << '\n' << "If you do not have the requested variable, input " << '\"' << "n" << '\"';
			cout << '\n' << "To input a number, type the number, and press Enter to continue.";
			cout << '\n' << '\n' << "ONLY ENTER 3 VALUES";
			cin.get();
		}
			
	system("CLS");
			
			cout << "a: ";
			getline(cin, invalue[0]);
				
				if (invalue[0] != "n" && invalue[0] != "N")
				{
				tvalue[i] = invalue[0];
				i++;
				}

			cout << "b: ";

				if (invalue[1] != "n" && invalue[1] != "N")
				{
				tvalue[i] = invalue[1];
				i++;
				}

			getline(cin, invalue[1]);
			cout << "c: ";
			getline(cin, invalue[2]);
				
				if (invalue[2] != "n" && invalue[2] != "N")
				{
				tvalue[i] = invalue[2];
				i++;
				}

			cout << "A: ";
			getline(cin, invalue[3]);

				if (invalue[3] != "n" && invalue[3] != "N")
				{
				tvalue[i] = invalue[3];
				i++;
				}
				
			cout << "B: ";
			getline(cin, invalue[4]);

				if (invalue[4] != "n" && invalue[4] != "N")
				{
				tvalue[i] = invalue[4];
				i++;
				}
			
			cout << "C: ";
			getline(cin, invalue[5]);

				if (invalue[5] != "n" && invalue[5] != "N")
				{
				tvalue[i] = invalue[5];
				i++;
				}

		system("CLS");
		cout << tvalue[0];
		cout << '\n' << tvalue[1];
		cout << '\n' << tvalue[2];
	cin.get();
	cin.get();
	return 0;
}


When I attempt to execute the program I get an error message while inputting numbers that says
"Unhandled exception at 0x1027cafa (msvcr100d.dll) in test.exe: 0xC0000005: Access violation writing location 0xcccccccc."



I am unsure what I am doing wrong.
1
2
3
4
5
6
7
8
9
			cout << "b: ";

				if (invalue[1] != "n" && invalue[1] != "N")
				{
				tvalue[i] = invalue[1];
				i++;
				}

			getline(cin, invalue[1]);

first read, then access invalue[1]...

string invalue[5]; getline(cin, invalue[5]);

Nope. Valid slots in this array are 0,1,2,3,4(five in total). Anything else results in access violation(array index out of bounds)
Topic archived. No new replies allowed.