Hello again... My problem is that my if statement isn't working as I believe it should. Here is a snippet of the for loop.

for(int m=0; m<num; m++)
	{
		if(begllts <= intarray[m] && intarray[m] <= endllts);
		{
			cout << setprecision(4) << showpoint <<
			dubarray[m] << "C" << stringarray[m]<< endl;
			total += dubarray[m];
			count ++;
		}
	}

The intarray[m] is a dynamic array for long long int. Begllts and endllts are inputed by the user and stored as long long ints. The only real problem is that it runs the if statement every time instead of when I define it.

Any ideas? If you need more information, let me know. I'm not good at the snippet part, so I always put just a little so as to not spam non-important stuff.

Ok, is this how your logic should read?

if the value of begllts is less than or equal to the value[m] inside the array and the value of the position m of the array is less than or equal to the value of endllts, then do this{}

Is that what you intended?

My Logic was supposed to go:
If the value of begllts is less than or equal to the value of array[m] AND endllts is greater than the value of array[m], then do so and so.

Edit: I've positioned it all sorts of ways... I don't seem to understand. Can you explain this one out?
I want each piece of data in that certain array, not where the array points to.

Edited 5 Years Ago by Rimojenkins: n/a

OH
I see

check your IF STATEMENT.. GET RID OF THE ;

if(begllts <= intarray[m] && intarray[m] <= endllts); //<--- that last ;, Get rid of it BAD, NEWBIE BAD .. :D

Edited 5 Years Ago by Saith: n/a

Comments
well spotted!!

My Logic was supposed to go:
If the value of begllts is less than or equal to the value of array[m] AND endllts is greater than the value of array[m], then do so and so.

Then it should be:

if(begllts <= intarray[m] && endllts > intarray[m])

Edit: I've positioned it all sorts of ways... I don't seem to understand. Can you explain this one out?
I want each piece of data in that certain array, not where the array points to.

You want too add values to intarray? What part do you not understand?

Edited 5 Years Ago by Akill10: n/a

// Original
if(begllts <= intarray[m] && intarray[m] <= endllts);

// Akill10 changed to
if(begllts <= intarray[m] && endllts >= intarray[m])

is the same exact thing. No difference, other than Akill10 got rid of the ; at the end of his if-statement.

Thank you Saith! I can't believe I left that. It is a big code and that didn't pop up as an error.

I didn't understand the error and I thought you were telling me that I was doing my coding incorrectly. Besides the ";", it works. Thank you though, have a good day!

(or rather, I didn't understand your analysis of the logic. Is the way I wrote it incorrect? It works now that I got rid of the ";")

What happens when you add the semicolon at the end of the if-statement, the if statement checks to see if the statement is true or false. It ends there. The block of code following the if-statement is interpreted as a new block of code, regardless if the if- statement was true or not, that will run.

/*
	Purpose: The semicolon at the end of the if-statement
	Name: Saith
	Date: 2/5/11
	*/

#include<iostream>
using namespace std;

int main() {

	if(4 > 5);   // we know this is false, but will run the following block of code anyway
	{
	cout << "hello world";
	}
	return 0;
}

Is a snippet of full program that will output hello world.

Oh, this will happen with for-loops as well.

for(int index = 0; index < 10; index++);
{
cout << "hello world";
}

The for-loop will run 10 times, but it will not process the block of code 10x as we expect. The semi-colon is preventing the block of code to output hello world the 10x we expect it to. By getting rid of the semi-colon, you make the following block of code part of the for-loop body; the block executing every time the for-loop loops.

This question has already been answered. Start a new discussion instead.