Thread: Troubleshooting Please

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    12

    Troubleshooting Please

    Just trying to get this code to get a seed, upper and lower bounds, the number of random numbers to generate so far. having a few bugs, any help would be much appreciated.

    #include <stdio.h>
    #include <stdbool.h>
    #include <stdlib.h>

    void myName(void);
    bool getInput(int* jSeed, int* jLowBnd, int* jHiBnd, int* jGenNumb);
    bool getSeed(int* jSeed);
    bool getBounds(int* jLowBnd, int* jHiBnd);
    bool getGenNum(int* jGenNumb);
    void genRandom(int seed, int LowBnd, int HiBnd, int GenNumb,
    int* jEven, int* jOdd, int* jNeg, int* jPos, int* jZero);
    void add2Counts(int randNum, int* jEven, int* jOdd,
    int* jNeg, int* jPos, int* jZero);
    void printResults(int Seed, int LowBnd, int HiBnd, int GenNumb, int Even,
    int Odd, int Neg, int Pos, int Zero);

    int main(void)
    {
    int jSeed, jLowBnd, jHiBnd, jGenNumb;
    int jEven,jOdd, jNeg, jPos, jZero;
    int Seed, LowBnd, HiBnd, GenNumb, Even, Odd;
    int Pos, Neg, Zero, randNum;

    myName();
    getInput(&jSeed, &jLowBnd, &jHiBnd, &jGenNumb);
    genRandom(Seed, LowBnd, HiBnd, GenNumb, &jEven,
    &jOdd, &jNeg, &jPos, &jZero);
    add2Counts(randNum, &jEven, &jOdd, &jNeg, &jPos, &jZero);
    printResults(Seed, LowBnd, HiBnd, GenNumb, Even, Odd, Neg, Pos, Zero);

    return 0;
    }

    void myName(void)
    {
    printf("\n**************************************** *******************");
    printf("\n**************************************** *******************");
    printf("\n** Joshua Yount **");
    printf("\n** and **");
    printf("\n** John King **");
    printf("\n**************************************** *******************");
    printf("\n**************************************** *******************\n");
    printf("\n\n");
    return;
    }

    bool getInput(int* jSeed, int* jLowBnd, int* jHiBnd, int* jGenNumb)

    {
    if(getSeed(jSeed)) printf("\nSuccess!\n");
    else printf("There was an error passing you seed value");

    if(getBounds(jLowBnd, jHiBnd)) printf("\nSuccess!\n");
    else printf("\nThere was an error passing the upper and lower bounds.\n");

    if(getGenNum(jGenNumb)) printf("\nSuccess!\n");
    else printf("There was an error passing the number of random numbers.\n");

    return;
    }

    bool getSeed(int* jSeed)
    {
    int seed;
    *jSeed = seed;
    printf("\nPlease enter a nonnegative seed value: ");
    scanf("%d", jSeed);

    if(seed < 0)
    printf("%d is a negative number, please only enter positive numbers.", seed);
    else;
    return;
    }

    bool getBounds(int* jLowBnd, int* jHiBnd)
    {
    int lowbnd, hibnd;
    *jLowBnd = lowbnd;
    *jHiBnd = hibnd;

    printf("\nPlease enter a lower bound number inbetween [-25,-1]");
    printf("and an upper bound number inbetween [1,25]");
    printf("seperated by a space");
    printf("\n");
    scanf("%d %d", jLowBnd, jHiBnd);

    if(-25 < lowbnd < -1 && 1 < hibnd < 25)
    {
    if(-25 > lowbnd > -1 && 1 < hibnd < 25)
    printf("Your lower bound number is outside of range [-25,-1].");
    else if(-25 < lowbnd < -1 && 1 > hibnd > 25)
    printf("Your upper bound number is outside the range [1,25]");
    else if(-25 > lowbnd > -1 && 1 > hibnd > 25)
    printf("Both you entered values are outside the range [-25,-1] & [1,25]");
    }
    else;
    return;
    }

    bool getGenNum(int* jGenNumb)
    {
    int gennumb;

    printf("\nPlease enter a number of random numbers to generate");
    printf("inbetween [10,50]:");
    printf("\n");
    scanf("%d", jGenNumb);
    gennumb = *jGenNumb;

    if(10 < gennumb < 50)
    {
    if(10 > gennumb)
    printf("The number you entered is less than 10:");
    else if(gennumb > 50)
    printf("The number you entered is greater than 50:");
    }
    else;
    return ;
    }

    void genRandom(int seed, int LowBnd, int HiBnd, int GenNumb,
    int* pEven, int* pOdd, int* pNeg, int* pPos, int* pZero)
    {
    int i;
    int randNum;

    srand((unsigned int)seed);
    for(i = 0; i < GenNumb; i++)
    {
    randNum = rand() % (LowBnd - HiBnd);
    printf("\n%d: %d", i, randNum);
    }
    printf("\n\n");
    return;
    }

    void add2Counts(int randNum, int* pEven, int* pOdd,
    int* pNeg, int* pPos, int* pZero)
    {
    }

    void printResults(int seed, int LowBnd, int HiBnd, int GenNumb, int even,
    int odd, int neg, int pos, int zero)
    {
    }

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    8
    It's hard to help if I don't know what errors you're getting.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    12
    ummm some of the tests aren't correctly working, and it is just saying success for the random number generator. Its not generating the numbers.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    << !! Posting Code? Read this First !! >>
    Also beware of these kinds of expressions:
    if (10 < gennumb < 50)
    While it is correct to write so in math, it is not in C.
    Basically, it evaluates to
    if ((10 < gennumb) < 50)
    And (10 < gennumb) will evaluate to a boolean (true or false; basically 1 or 0), and then that will be compared to < 50, so you'll see you will get the wrong result.
    You need to be explicit. If you want gennumb to be bigger than 10 and lesser than 50, then you must write
    if (gennumb > 10 && gennumb < 50)
    Last edited by Elysia; 03-03-2010 at 02:39 AM.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My program needs troubleshooting...
    By Rockiroad278 in forum C Programming
    Replies: 7
    Last Post: 12-16-2007, 08:34 PM
  2. confused n need urgent troubleshooting on C++ program
    By tezr87 in forum C++ Programming
    Replies: 2
    Last Post: 06-01-2006, 04:38 AM
  3. Troubleshooting code
    By bcianfrocca in forum C++ Programming
    Replies: 11
    Last Post: 11-17-2005, 05:46 PM
  4. Troubleshooting
    By hockeydrummer88 in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2005, 02:17 PM