
Originally Posted by
Bl4Ck.KiD...
Thanks To Evil Loco
Code:
//Simple Arrays By Bl4Ck.KiD...
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
cout << "Bl4Ck.KiD...'s Simple Arrays Setup" << endl << endl;
cout << "Hits In The Game" << endl;
int hits [5];
hits [0]=10;
hits [1]=21;
hits [2]=34;
hits [3]=14;
hits [4]=65;
hits [5]=36;
cout << hits[0] - hits[5] + hits[1] / hits[4] * hits[2] + hits[3] << endl << endl;
cout << "Home Runs" << endl;
int homeruns [4];
homeruns [0]=5;
homeruns [1]=3;
homeruns [2]=0;
homeruns [3]=1;
cout << homeruns[0] + homeruns[1] + homeruns[2] + homeruns[3] <<endl <<endl;
system("pause");
return 0;
}
Jakey likey, Jakey likey. Here's some helpful tips:
• This piece of code works but it's technically not right:
Code:
int hits [5];
hits [0]=10;
hits [1]=21;
hits [2]=34;
hits [3]=14;
hits [4]=65;
hits [5]=36;
When you declared you were making an array (int hits [5]), the 5 means there are going to be only five values in it. You have 6.
is technically it's own array. This works when assembled because the computer automatically gives it a somewhat random value. To prove this I made the hits [5]=36 into a comment and ran it, it outputed 280 for the value of hits [5]. After that I ran it without it commented it outputted 36. So it does work but it's technically wrong. In arrays, you define how many variables, the number you define minus one is the last number you can rightfully have when calling variables from that array. In an array 0 counts as it's own number so an array [2] would have 0 and 1, an array [3] would have 0, 1, and 2. An array [4] would have 0, 1, 2, 3. Hence an array [5] would be 0, 1, 2, 3, 4, and so on. You should get the point.
• You do not need to include cmath
• "\n" means new line, same exact effect as end line (endl). You will likly use it more often when your programs get larger and larger and you will be doing anything to optimize the file size.
Rather then:
Code:
cout << "Bl4Ck.KiD...'s Simple Arrays Setup" << endl << endl;
and
Code:
cout << "Hits In The Game" << endl;
and
Code:
cout << hits[0] - hits[5] + hits[1] / hits[4] * hits[2] + hits[3] << endl << endl;
and
Code:
cout << homeruns[0] + homeruns[1] + homeruns[2] + homeruns[3] <<endl <<endl;
Consider:
Code:
cout << "Bl4Ck.KiD...'s Simple Arrays Setup\n\n";
and
Code:
cout << "Hits In The Game\n";
and
Code:
cout << hits[0] - hits[5] + hits[1] / hits[4] * hits[2] + hits[3] << "\n\n" ;
and
Code:
cout << homeruns[0] + homeruns[1] + homeruns[2] + homeruns[3 ]<< "\n\n";
• It's good to have consistent spacing. In most your your "<< endl <<" you wrote it like that but in one you wrote "<<endl <<". When your programs become very large and your trying to optimize them all you can your not going to want to looking for every endl using find. If your spacing was consistent you could easily use the replace feature.
Example:
Code:
//stuff here
cout << "blah blah blahh" << /* some variable stuff here */ << "blah blah"<<endl << endl << endl;
This wouldn't very easy to use the replace feature.
Code:
//stuff here
cout << "blah blah blahh" << /* some variable stuff here */ << "blah blah" << endl << endl << endl;
This would because you could optimize using the replace feature by typing:
Code:
" << endl << endl << endl;
into the find what box and then put
into the replace with box.
• P.S: It says thanks to Evil Loco but you took credit for it in the actual program itself... He may have just helped you or something in which case it's fine.
Hitting the Rep+ and Thanks button never hurt anyone ;)
Off Topic: I signed up to your site, I made a few posts including a coder application but now it says my username doesn't exist or something... Please help? Maybe your system is right but FireFox remembers it being s2h6699... Check in the coder application for the person that programs in SCAR to see if I'm just stupid or your system isn't working properly.
Bookmarks