C++ if statements

Status
Not open for further replies.
Which could be simplified to
Code:
for(int i=0;i<10;i++)if(i!=7)cout<<"HI"<<endl;

:p but that's probably counterproductive in terms of readability vs simplicity
 
Ug I hate to be so problematic but my array has a weird issue.

Code:
    int array[3]={34,98,1};
    cout<<array[1]<<endl;
    cout<<array[2]<<endl;
    cout<<array[3]<<endl;

The result of the program is: 98
1
4283312

Not one of the items inside the array is 4283312. Help!
 
Arrays start at 0 not 1, there is no array[3] in that example. Have you researched this at all? First google result of "C++ arrays" below
Arrays - C++ Documentation
array[0] = 34
array[1] = 98
array[2] = 1

don't be lazy ;) we'll help if you get stuck, but you have to do some work yourself!
 
If you use google, or whichever your favorite search engine is, you would be able to find the answer to your questions faster since you wouldn't need to wait for one of us to read and respond.

There are all kinds of C++ tutorial and reference sites out there. As SP suggests, don't be lazy, do your own research first.
 
Arrays start at 0 not 1, there is no array[3] in that example. Have you researched this at all? First google result of "C++ arrays" below
Arrays - C++ Documentation
array[0] = 34
array[1] = 98
array[2] = 1

don't be lazy ;) we'll help if you get stuck, but you have to do some work yourself!

I had no clue about that. I thought it started at 1... I feel bad anyways about how many problems I have. learncpp isn't very clear on somethings.
 
Scrolling down to "Arrays (Part 1)" on the site you linked to, I read this
The first element of our array is named anTestScores[0]. The second is anTestScores[1]. The tenth is anTestScores[9]. Note that in C++, arrays always count starting from zero! This means an array of size N has array elements 0 through N-1. This can be awkward for new programmers who are used to counting starting at 1.
:thumbsup:
 
New language with different syntax than I am used to. I usually work with a modified version of Lua as well as for websites HTML but learning PHP. The modified version of Lua has a different syntax than I am used to. Kinda like going from English to Wingdings I guess, same language but looks completely different.
 
Status
Not open for further replies.
Back
Top Bottom