Whats wrong at the bottom

This is a discussion on Whats wrong at the bottom within the C++ Programming forums, part of the General Programming Boards category; Code: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <iomanip.h> #include <iostream.h> #include <time.h> #define DARR_LEN 5 void main() { double ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    1

    Angry Whats wrong at the bottom

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <iomanip.h>
    #include <iostream.h>
    #include <time.h>
    
    #define DARR_LEN 5
    
    void main()
    {
        double dArr[DARR_LEN];
    
        long lArr[7]={100000, 134567, 123456, 9, -234567, -1, 123489};
    
        int iArr[3][5];
    
        char sName[30]="Andrew Dundas";
    
        short cnt1, cnt2;
        long double total;
    
        long highest;
    
        srand(0);
        for(cnt1 = 0; cnt1 < DARR_LEN; cnt1++)
        {
            dArr[cnt1] = rand();
            cout <<dArr[cnt1]<<" ";
        }
        cout <<endl;
    
    
        total = 0.0;
        for(cnt1 = 0; cnt1 < DARR_LEN; cnt1++)
            total += dArr[cnt1];
    
        cout <<"Total is: "<< total <<endl;
        cout <<"Average is: "<< total/DARR_LEN <<endl;
    
        for ( cnt1 = 1,  highest = lArr[0]  ;  cnt1 < 7 ;  cnt1++ )
        {
            if (lArr[cnt1] > highest)
                highest = lArr[cnt1];
        }
    
        cout <<"The highest number is: "<<highest<<endl;
    
        srand( (unsigned) time(NULL));
        for (cnt1 = 0; cnt1 < 3; cnt1++)
        {
            for(cnt2 = 0; cnt2 < 5;cnt2++)
                iArr[cnt1][cnt2] = rand()%49+1;
        }
        
        for (cnt1 = 0; cnt1 < 3; cnt1++)
        {
            cout<<"Row "<<cnt1+1<<": ";
            for(cnt2 = 0; cnt2 < 5;cnt2++)
                cout <<setw(3)<<iArr[cnt1][cnt2];
            cout<<endl;
            
        }
        
        for (cnt1 = 0; cnt1 < 5; cnt1++)
        {
            cout<<"Column "<<cnt1+1<<": ";
            for(cnt2 = 0; cnt2 < 3;cnt2++)
                cout <<setw(3)<<iArr[cnt2][cnt1];
            cout<<endl;
            
        }
        
        cout <<"Enter Name ";
        cin.getline(sName, 30);
        
        cnt1 = 0;
        while (sName[cnt1] != '\0')
        {
            cout << (int)sName[cnt1] <<endl;
            cnt1++;
        }
    
        strcpy(sName, "Albert Einstein");
    
    
        cout << (int)sName[11]<<endl;
    
    //Define pointer to a double, pdArray.
    	double *pdArray;
    
    //Assign the pointer, pdArray, to contain the address of the 
    //double array, dArr.
    	pdArray = dArr[DARR_LEN];
    
    //Use the array name, dArr, to print out the array elements with 
    //subscript notation, [ ].
    	cout << dArr[DARR_LEN]<<endl;
    
    //Use the pointer to print out the array elements with 
    //pointer notation while not changing the  pointer itself.
    //Use a for loop.
    	for ( cnt1 = 0; cnt1 < 5; cnt1++, pdArray++)
    		cout <<*pdArray<<"  ";
    	cout <<endl;
    
    //Use the pointer to print out the array elements with pointer 
    //notation but change the 
    //pointer	to point to the actual array element rather than the 
    //method in 18.
    	for (cnt1 = 0; cnt1 < 5; cnt1++)
    		cout <<*(pdArray+cnt1)<<"  ";
    	cout <<endl;
    
    //Use the array name for the double array and 
    //pointer notation to print the entire array
    	for (cnt1 = 0; cnt1 < 5; cnt1++)
    		cout << *(dArr+cnt1)<<"  ";
    	cout<<endl;
    
    
    
    }

    Code tags added by Hammer

  2. #2
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    *rubs eyes*

    code tags?
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >#include <iostream.h>
    I slowed down right about here.

    >#define DARR_LEN 5
    I said "Wha?" right about here.

    >void main()
    This is where I stopped. main returns int, not void. If you want further help than that I suggest you place your code in code tags.

    -Prelude
    My best code is written with the delete key.

  4. #4
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    call me newbie, but ive always wondered whats wrong with iostream.h. isnt that required in order to use cout, cin, etc..?
    I came up with a cool phrase to put down here, but i forgot it...

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but ive always wondered whats wrong with iostream.h.
    There's nothing wrong with iostream, but the .h extension is old C++, which shouldn't be used if your compiler supports the new headers (I don't know of any popular ones that don't).

    -Prelude
    My best code is written with the delete key.

  6. #6
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    oh, well i thought i heard someone making fun of someone else for including iostream. maybe i misunderstood them.
    I came up with a cool phrase to put down here, but i forgot it...

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    #include <iostream> is correct, and, if anyone makes fun of you, send them to us.

    I'm guessing you misunderstood. Where the controversy comes in - legitimate, or otherwise - is in including the Standard headers, like <iostream>, and then tossing in "using namespace std;".

    You may want to research this one yourself. (It's been done to death.) Your call.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

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