Thread: Stupid Question 3

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    34

    Stupid Question 3

    // This program is to use the bucket sort method to rearrange given numbers.

    #include <iostream.h>
    #include <fstream.h>

    using std::cout;
    using std::cin;
    using std::endl;

    #include <iomanip.h>

    using std::setw;
    using std::setiosflags;
    using std::setpercision;

    int main()
    {
    ifstream infile ( "/u1/rfulk/values");
    const int size = 8;
    const int a = 10;
    int digitCnt, number, num2, z, d, e, f, temp;
    z = 0;
    digitCnt = 0;
    num2 = 0;
    number = 0;
    d = 0;
    e = 0;
    f = 0;
    int num1[size] = { 0 };
    for ( int x = 0; x < size; x++ )
    infile >> num1[x];
    for ( int x = 0; x < size; x++ )
    {
    if ( num1[x] != 0 )
    {
    cout << "Look, here's value " << x << ": " << num1[x] << endl;
    z++;
    }
    }
    cout << z << endl;

    int num3[a][z];

    for ( int x = 0; x < a; x++ )
    {
    for ( int y = 0; y < z; y++ )
    num3[x][y] = 0;
    }

    for ( int x = 0; x < z; x++ )
    {
    number = num1[x];
    e = d;
    digitCnt = 0;
    while(number)
    {
    number=number/10;
    digitCnt++;
    }
    d = digitCnt;
    if ( e > d )
    f = d;
    }

    int u;
    int b = 10;
    int c = 1;

    for ( int w = 1; w <= 8; w++ )
    {
    u = 0;
    for ( int x = 0; x < z; x++ )
    {
    num2=num1[x]%b/c;
    num3[num2][x] = num1[x];
    }

    for ( int x = 0; x < 10; x++ )
    {
    for ( int y = 0; y < 6; y++ )
    {
    if ( num3[x][y] != 0 )
    {
    num1[u] = num3[x][y];
    u++;
    }

    }
    }
    c = c * 10;
    b = b * 10;

    cout << "Here is your numbers sorted through sort #" << w << endl;
    for ( int x = 0; x < z; x++ )
    cout << setw(10) << num1[x];
    cout << endl;
    }

    return 0;
    }



    Ok here is the problem. The program compiles, then I run it, it goes through 2 loops and then dumps the last number and jumps out with a segmintation fault. Does anyone have a soultion to remeady this problem?
    http://members.ebay.com/aboutme/the_ski/

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Ok Please IGNORE this post. Corrected Problem...

    Still need help on the other post though.
    http://members.ebay.com/aboutme/the_ski/

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    what is your output supposed to look like? when i ran the code it was all kindsa screwy, just from what i see here, my initial reaction is that some value isnt being set correctly

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    ha! you corrected it about 20 seconds before i posted my reply, oh well, ill getcha next time

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Yes the output is supposed to be a little screwy as well. But Oh well. Only 2 more weeks of this class. But speaking of classes, That is the topic we are working on now. Any suggestions for a blackjack game using classes and structures?

    Don't answer that. Will begin working on it in a couple of days.

    Need to simmer the brain down tonight and tomorrow after dealing with this damn program.

    Thanks to all for your help.

    The Ski
    http://members.ebay.com/aboutme/the_ski/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM