Need serious help, I am a beginner guys.

I cant figure out whats wrong, Im a beginner so i dont know many things on c++.

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
int x;
int z;
string y;
std::string mystr[y];


cout << "Enter first number";
cin >> x;
cout << "Calculations";
getline(cin, mystr[y]);
cout << "Enter your second number";
cin >> z;

if(mystr[y] == "addition")
{
cout << "Your answer is ";
cout << x + z;
return 0;
}
else if(mystr[y] == "subtract")
{
cout << "Your answer is ";
cout << x - z;
return 0;
}
else if(mystr[y] == "times")
{
cout << "Your answer is ";
cout << x * z;
return 0;
}
else if(mystr[y] == "division")
{
cout << "Your answer is ";
cout << z / x;
return 0;
}
}

I get this message:
..\Firstprogram.cpp:40:15: error: no match for 'operator[]' (operand types are 'std::string [1] {aka std::basic_string<char> [1]}' and 'std::string {aka std::basic_string<char>}')
else if(mystr[y] == "division")
Why is mystr an array? And since this is C++ array sizes must be compile time constants. Also you can't use a string as an index for an array.
You are confusing string with char[]. Just change
1
2
3
4
string y;
std::string mystr[y];
// To
std::string mystr;

along with every other instance of mystr[y] and that part will be good. You do not need to prefix string with std:: either since you have
using namespace std;
You will also have trouble with division due to integer division witch will truncate everything after the decimal place. There is still at least one other problem, but it will not stop your program from working as expected.
Thank you very much for repplying so quick! Ill try your suggestions. Also, i tried openning another program with no apparent bugs but it just instantly stopped working, any help please?
Nevermind what I repplied earlier. I found a fix.
Topic archived. No new replies allowed.