what does this mean

This is a discussion on what does this mean within the C++ Programming forums, part of the General Programming Boards category; im getting the following error on a for loop, what does this mean? Code: arning C4552: '<' : operator has ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    494

    what does this mean

    im getting the following error on a for loop, what does this mean?
    Code:
    arning C4552: '<' : operator has no effect; expected operator with side-effect
    When no one helps you out. Call google();

  2. #2
    Registered User Sake's Avatar
    Join Date
    Jan 2005
    Posts
    89
    Can you show the code that causes this error?
    Kampai!

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    well here it is, Andy helped me figure out the reading part of the file but now im trying to get the average of the numbers in the array. so here is what i got so far.

    Code:
    #include	<iostream.h>
    #include	<fstream>
    #include	<stdlib.h>
    using namespace std;
    
    const int	FILENAMELEN = 30, ARRAYLEN = 4;
    
    // The class array
    class	array	{
    public: // These functions are avaiable for use outside the class 
    	inline int	getsize()	{return(size);}
    	int        readarray();
    	float findaverage();
    	array();
    
    private:
    	//Private - available only to member functions
    	int	x[ARRAYLEN];
    	int	size;
    	int j;
    	int numbers[20];
    	int count;
    	float average;
    	float sum;
    	char filename[FILENAMELEN];
    	char inchar;
     
    };
    
    //initialization constructor 
    array::array(void)
    {
    	size = 0;
    }
    
    int array::readarray()
    {
    	ifstream infile;
    	char filename[FILENAMELEN];
    	char inchar;
    
    	cout<<"Enter filename->" <<'\t';
    	cin>> filename;
    	//openfile
    	infile.open(filename);
    	//if you cant open the file, print error message
    	if (!infile)
    	{
    		cerr<< "Cannot open " <<filename << endl;
    		exit(1);
    	}
    
    	//Read the file character
    	while (!infile.eof())
    	{
    		inchar = infile.get(); //this reads in even whitespaces
    		cout << inchar; //display it on screen
    	}
    	infile.close();
    	return(0);
    }
    
    float array::findaverage()
    {
    	int j;
    	float average;
    	sum =0.0;
    	for (j<0; j<count; j++)
    	{
    		sum+=numbers[j];
    	}
    	average = sum/j;
    	cout << "The average is		"<< average <<endl;
    	return  0;
    
    }
    
    
    int	main()
    {
    	array	myarray;
    	myarray.readarray();
    	myarray.findaverage();
    	return(0);
    }
    When no one helps you out. Call google();

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    for (j<0; j<count; j++)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    ah yes, jesus im blind

    ok i corrected the for loop but now the result is ugly, no errors, no warnings, but an ugly wrong result
    Code:
     -1. #IND
    any ideas?
    Last edited by InvariantLoop; 02-12-2005 at 06:46 PM.
    When no one helps you out. Call google();

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
     -1. #IND
    This means the result was not a number/indeterminate. You get this result when the operation is not mathematically defined.
    http://stevehollasch.com/cgindex/coding/ieeefloat.html
    http://www.google.com/search?q=%23INDeterminate+nan

    You are getting this result because you are performing maths on an array of numbers that have not been initialised.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    wait im confused, the numbers contained in the array have not been initialized? I am able to read the array and display the values that is holding, why cant i operate on those values since im able to read them? any ideas how i can go about it then so i can work on those numbers?
    When no one helps you out. Call google();

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    >>I am able to read the array and display the values that is holding

    Review readarray() again. I see where it reads the material in the file into a single char and displays that char on the screen. But...I don't see where it stores the material read in anywhere, let alone read in an int that could be stored in numbers[] such that the values in numbers[] could then be used in findaverage().

    Read the file contents into an int and store the value of the int in numbers[], or better, in my opinion, use a loop to store the value read from the file directly into numbers[], and get rid of !infile.eof() as the conditional of the loop, which is likely to get you into trouble (likely to read in one more value than you had planned on).
    You're only born perfect.

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    i searched on the forums can i use atoi something for this? to convert the char into int? someone give me a few hints please
    When no one helps you out. Call google();

  10. #10
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Once you read your file into an array, you can use atoi to convert it into a number. Here is an example prog to demonstrate this:
    Code:
    #include <iostream>
    #include <ctype.h>
    #include <cstdlib>
    
    using namespace std;
    
    int main() {
    
        char myString[5] = {'1', ' ', '2', ' ', '3'};
        int myInt[5] = {0};
        int count = 0, sum = 0;
    
        for(int i = 0; i < 5; i++){
            if(isdigit(myString[i])){
                myInt[count++] = atoi(&myString[i]);
            }
        }
        
        for(int i = 0; i < count; i++){
            sum += myInt[i];
        }
        cout << endl << sum << endl;
    
        return 0;
    }
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    ok ill work on that. thanks man
    When no one helps you out. Call google();

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    for the love of god i still cant figure this out, can someone take a look at my code please the reading is the only thing holding me back, i created another function similiar to findaverage() but if i cant read the numbers then i cant do any work on that either.
    When no one helps you out. Call google();

  13. #13
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Ok here is your while loop where you are reading from the file:
    Code:
    //Read the file character
    while(!infile.eof())
    {
         inchar = infile.get(); //this reads in even whitespaces
         cout << inchar; //display it on screen
    }
    infile.close();
    Notice you are not storing your information anywhere. Somewhere in that while loop you are going to need to store the char in inchar into an array or some form of container.

    So ask yourself, Do I know how large I need to make the array?(aka how many characters are going to be read from the file)

    If you do simply create a char array as one of your private members and then add inchar to it like so:
    Code:
     
    //Defined in class
    char fileInput[fileSize];
    
    //In your read function
    int currentChar = 0;
    
    //Read the file character
    while(!infile.eof())
    {
         fileInput[currentChar] = infile.get(); //this reads in even whitespaces
         cout << fileInput[currentChar]; //display it on screen
         currentChar++;
    }
    infile.close();
    Now if you don't know the size you can either size the array dynamically with the new operator or the easiest way of handling this in C++ is to use a container object such as a vector.

    I have a simple prog that loads a file into a vector. Let me know if you want to see it, I am assuming that you want to figure this out for yourself though.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21