Arrays Dev-c++ (please helps)

This is a discussion on Arrays Dev-c++ (please helps) within the C++ Programming forums, part of the General Programming Boards category; Hey can someone please help me with my project? I attached the instructions + .cpp file , I can't seem ...

  1. #1
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76

    Unhappy Arrays Dev-c++ (please helps)

    Hey can someone please help me with my project? I attached the instructions + .cpp file , I can't seem to get it to work correctly.



    Thank you!!
    Attached Files Attached Files

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    Indeed, your function calls are wrong - read up on them. You use () when calling functions and you must also pass an argument for your functions.
    Since this is C++, I'd rather you try to use vector instead of built-in arrays too.
    Oh and array is a keyword. Best not use that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,410
    Oh and array is a keyword.
    array is not a keyword, but it is not a particularly descriptive name since it says the obvious.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    array is a keyword in C++ CLI, Microsoft's own C++ crap, so it's a keyword in Visual Studio. It's not in C/C++, though, but I'd still avoid it.
    Maybe that clears up some confusion.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76

    Unhappy

    What function calls? and I used arrays cause it is the name of the project >_<

    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    //the function prototypes 
    void getData(int array[][2]);
    double averageHigh(int array[][2]);
    double averageLow(int array[][2]);
    int indexHighTemp(int array[][2]);
    int indexLowTemp(int array[][2]);
    
    int main()
    {
        int months[12][2]; 
          
              
            
        
       //telling the user the average high temperature
        cout << "Average high temperature:"<<averageHigh<< endl;
       
       //telling the user the average low temperature
        cout << "Average low temperature:"<<averageLow<< endl;
       
        //telling the user the highest temperature
        cout << "Highest temperature:"<<indexHighTemp<< endl;
        
        //telling the user the lowest temperature
        cout <<"Lowest temperature:"<<indexLowTemp<< endl;
        cout<<"Name"<< endl;
                 
        getch ();
        return 0;
    }
    
    void getData(int array[][2])
    {
         /* asks the user to input the highest and lowest temperatures 
         and contains the for loop to store it and a counter.*/
        
        cout << "Please enter highest temperatures for each month." << endl;
        for(int i=0; i<12; i++)
            cin >> array[i][0];
        
       cout << "Please enter lowest temperatures for each month." << endl;
        for(int i=0; i<12; i++)
           cin >> array[i][1];      
    }
    //does the math for the average high temperatures 
    double averageHigh(int array[][2])
    {
        int sumh = 0;
        
        for(int i=0; i<12; i++)
            sumh += array[i][0];
        return sumh/12.0;
    }
    //does the math for the average low temperatures, also contains a for looop
    double averageLow(int array[][2])
    {
        int suml = 0;
        
        for(int i=0; i<12; i++)
            suml += array[i][1];
        return sum1/12.0;
    }
    //a nested for loop to find the highest and lowest temperature
    int indexHighTemp(int array[][2])
    {
        int highTemp = 0; 
        
        for(int i=0; i<12; i++)
        {
            if(array[i][0] > highTemp)
            {
                highTemp = array[i][0];
                
            }
        }
        return highTemp;
    }
    
    int indexLowTemp(int array[][2])
    {
        int index = 0;
        int lowTemp = array[0][1];     
        for(int i=1; i<12; i++)
        {
            if(array[i][1] < lowTemp)
            {
                lowTemp = array[i][1];
                index = i;
            }
        }
        return lowTemp;
    }

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    Quote Originally Posted by lifeis2evil View Post
    Code:
    int months[12][2];
    In this example it's fine, but consider std::vector otherwise.
    Quote Originally Posted by lifeis2evil View Post
    Code:
          //telling the user the average high temperature
        cout << "Average high temperature:"<<averageHigh<< endl;
       
       //telling the user the average low temperature
        cout << "Average low temperature:"<<averageLow<< endl;
       
        //telling the user the highest temperature
        cout << "Highest temperature:"<<indexHighTemp<< endl;
        
        //telling the user the lowest temperature
        cout <<"Lowest temperature:"<<indexLowTemp<< endl;
    What function calls????? What are these if not function calls?
    You're doing it wrong - you're printing the address of the function (or if you'd used Visual Studio 2005 or another compiler, you'd get a compile error because that isn't standard!)!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    Quote Originally Posted by Elysia View Post
    In this example it's fine, but consider std::vector otherwise.


    What function calls????? What are these if not function calls?
    You're doing it wrong - you're printing the address of the function (or if you'd used Visual Studio 2005 or another compiler, you'd get a compile error because that isn't standard!)!

    I can't use vector stuff cause I haven't learned it, and my teacher calls the "function calls" output to screen?? so the out put to screen is function calls?

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    std::vector is part of the STL. Very, very useful. I suggest you learn it when you have time.
    A function call is when you call a function - simple enough

    Code:
    int foo()
    {
    	return 6;
    }
    
    int main()
    {
    	int myint = foo(); // Calls function - aka function call.
    	cout << myint; // Prints 6 to screen.
    	cout << foo(); // Calls function - aka function call. Prints 6 to screen.
    	cout << foo; // Prints the function ADDRESS. Where the function is located in the memory (if it compiles at all)!
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    Quote Originally Posted by Elysia View Post
    std::vector is part of the STL. Very, very useful. I suggest you learn it when you have time.
    A function call is when you call a function - simple enough

    Code:
    int foo()
    {
    	return 6;
    }
    
    int main()
    {
    	int myint = foo(); // Calls function - aka function call.
    	cout << myint; // Prints 6 to screen.
    	cout << foo(); // Calls function - aka function call. Prints 6 to screen.
    	cout << foo; // Prints the function ADDRESS. Where the function is located in the memory (if it compiles at all)!
    }
    But aren't they something like this? not sure if i've ever seen them the other way
    Code:
        getData(array[i][0],array[i][1]); 
    	averageHigh(sumh); 
    	averageLow(suml); 
    	indexHighTemp(highTemp); 
    	indexLowTemp(lowTemp);

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    You really don't understand functions at all. Have you read tutorials/books on them?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    No, I'm not majoring in Programing I just had to take the class..

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    http://www.cprogramming.com/tutorial/lesson4.html
    You can't use a tool if you don't know how to use it. Read up, friend. Functions are your friends.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    I did a function program before but not with arrays

    Is it something like this?
    Code:
    int main()
    {
        int months[12][2]; 
            
        getData(array[i][0],array[i][1]); 
    	averageHigh(sumh); 
    	averageLow(suml); 
    	indexHighTemp(highTemp); 
    	indexLowTemp(lowTemp); 
       
            
        
       //telling the user the average high temperature
        cout << "Average high temperature:"<<averageHigh[sumh]<< endl;
       
       //telling the user the average low temperature
        cout << "Average low temperature:"<<averageLow[suml]<< endl;
       
        //telling the user the highest temperature
        cout << "Highest temperature:"<<indexHighTemp[highTemp]<< endl;
        
        //telling the user the lowest temperature
        cout <<"Lowest temperature:"<<indexLowTemp[lowTemp]<< endl;
        cout<<"Name"<< endl;
                 
        getch ();
        return 0;
    }

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    No, the functions take only ONE argument. Did you read the tutorial properly?
    And when passing arguments, you type the NAME only. You are passing the entire array, not some subset or index. Re-read your function argument list.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    I don't understand the tutorial...

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 04:31 AM
  2. Vertex Arrays
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 01-08-2006, 12:24 AM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 12:48 PM

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