Thread: Arrays Dev-c++ (please helps)

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by lifeis2evil View Post
    I don't understand the tutorial...
    It would help if you asked a specific question. Like what you don't understand about functions.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It would also help to get a grasp of the language before you use it. You don't drive a car before you know how to operate it!
    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. #18
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    is this correct?

    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]; 
        
        getData(months);
       //telling the user the average high temperature
        cout << "Average high temperature:"
                  << averageHigh(months) << endl;
       
       //telling the user the average low temperature
        cout << "Average low temperature:"
                  << averageLow(months) << endl;
       
        //telling the user the highest temperature
        cout << "Highest temperature:"
                  << indexHighTemp(months)  << endl;
        
        //telling the user the lowest temperature
        cout << "Lowest temperature:"
                  << indexLowTemp(months)  << 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 sumHigh = 0;
        
        for(int i=0; i<12; i++)
            sumHigh += array[i][0];
    
        return sumHigh/12.0;
    }
    //does the math for the average low temperatures, also contains a for looop
    double averageLow(int array[][2])
    {
        int sumLow = 0;
        
        for(int i=0; i<12; i++)
            sumLow += array[i][1];
    
        return sumLow/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];
                
            }
        }
        getch();
        return highTemp;
    }
    
    int indexLowTemp(int array[][2])
    {
        int lowTemp = array[0][1];     
        for(int i=1; i<12; i++)
        {
            if(array[i][1] < lowTemp)
            {
                lowTemp = array[i][1];
                
            }
        }
        getch();
        return lowTemp;
    }

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, this looks correct. Does it work?
    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. #20
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76

    Talking

    Yes it does =] lol the thing that was mostly confusing me were the arrays -_-

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, 05:31 AM
  2. Vertex Arrays
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 01-08-2006, 01:24 AM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10: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, 01:48 PM