First, please use code tags when posting code. See
http://www.cplusplus.com/articles/jEywvCM9/
You do declare the w as an array of integers. There is no formatted input operator that would populate a whole array.
The wording of your couts hints that you intend to read just one integer. If the w has e integers, which of them you want to store the value in?
That is not the only problem.
You declare two arrays that have e elements each. The arrays are statically allocated. The compiler has to know during compilation what the e is. It cannot, for the user is not there (and every run of the program can have different e). C++ requires dynamic memory allocation for this situation. The C++ standard library has
std::vector
container that is a dynamically allocated array.
See
http://www.cplusplus.com/reference/vector/vector/operator[]/ for example.
A name is an array of characters, but how long can one name be? Again, dynamic allocation is required. Again, the library has an easy solution,
std::string
. See
http://www.cplusplus.com/reference/string/string/operator%3E%3E/
You seem to want to store the wage for each of e employees. You create an array for e wages. You create it inside a loop. The array exists only to the end of the body of the loop. To the end of the iteration. You repeat this creation and destruction e times. No wages are stored anywhere after the loop.
Solution. Create the "array" before the loop. Outside the loop. Then it exists after the loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <string>
#include <vector>
#include <iostream>
int main()
{
int e = 0;
std::cin >> e;
std::vector<std::string> names( e );
for ( int c = 0 ; c < e ; ++c ) {
std::cin >> names[c];
}
std::cout << "=======\n";
for ( auto name : names ) {
std::cout << name << '\n';
}
return 0;
}
|