You should use the forum's <> Format to put your code in code format to make it readable.
For your purposes, I suggest just putting
using namespace std; in a new line after your #include <iostream>, but you also have a problem with having "endl" in a cin statment, as explained in Edit 2.
Edit: Also, just make it
1 2 3 4
|
int main()
{
//code
}
|
at the start of your main function.
Edit 2:
You are using the >> operator for cin, but then you have "endl" in the same line , which should be used with cout << only. You also have a semicolon after the endl, so your next line makes no sense to the compiler.
Make
1 2
|
std::cin >> data[1] >> data[2] >> data[3] >> endl;
data[4] >> data[5];
|
Be
1 2
|
std::cin >> data[0] >> data[1] >> data[2] >>
data[3] >> data[4];
|
Arrays/Vectors are base-0, so the first element in data is data[0], and data[5] is unpredictable as it isn't defined in the array. Also, if you use a semicolon, that ends the cin input, so your next line doesn't make sense to the compiler.
Sorry I quickly wrote those edits, here is what your code should look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
int main()
{
int data[5]; // The data to count 3 and 7 in
int seven_count = 0; // Number of sevens in the data
int three_count = 0; // Number of threes in the data
std::cout << "Enter 5 numbers\n" << std::endl;
std::cin >> data[0] >> data[1] >> data[2] >> data[3] >> data[4];
for (int index = 0; index <= 4; ++index)
{
if (data[index] == 3)
++three_count;
if (data[index] == 7)
++seven_count;
}
std::cout << " Threes " << three_count << " Sevens " << seven_count << std::endl;
return 0;
}
|
Other notes:
'\n' should be double quotation marks, not single (also fixed in above code, well I just deleted it since it is useless at the end of a program to have 2 line enders). I also deleted your global variable declarations and moved them into the corresponding line in your main function. You can keep it your way if you want, though I don't see the point.
I quickly made a bunch of edits after making my original post, so if you don't understand something specific, feel free to ask.