Thread: Galton Box C code Programming

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    Post Galton Box C code Programming

    Hi,
    I have made a code for high school project about the Galton box.However,the code is not executing properly and there are a lot of #s appearing at the back.

    Here is the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <conio.h>
    #include <stdbool.h>
    
    
    
     int intchecker(float x)
        {
    
        if (floor(x)==x && ceilf(x)==x)
        {
            return 0;
        }
        else {
                    return 1;
        }
    
    }
    
    int main(){
        char line[] = " +----+----+----+----+----+----+----+----+----+----+---+";
        char numbers[] = " 0    5    10   15   20   25   30   35   40   45   50";
        float balls,slots;
        int slotarry[9],tlevel,ballnum,column,lcounter=0,slotsduplicate=1,y;
        srand(time(NULL));
        int r;
    
        printf("Galton Box Assignment 3\n");
        printf("Enter the number of balls 5 to 100: ");
        scanf("%f",&balls);
        while (balls>100 || balls<5) {
            printf("\nInput not in valid range");
            printf("\nRe-enter the number of balls 5 to 100: ");
            scanf("%f",&balls);
        }
        while (intchecker(balls)==1) {
            printf("\nInput is not an integer. Please try again.");
            printf("\nEnter the number of balls [5-100]: ");
            scanf("%f",&balls);
        }
    
        printf("Enter the number of slots [2-10] : ");
        scanf("%f",&slots);
    
        while (slots>10 || slots<2) {
            printf("\nInput is not within the range. Please try again.");
            printf("\nEnter the number of slots [2-10] : ");
            scanf("%f",&slots);
        }
        while (intchecker(slots)==1) {
            printf("\nHow can there be a fraction of a slot? Please re-enter slot number.");
            printf("\nEnter the number of slots [2-10] : ");
            scanf("%f",&slots);
        }
    
        tlevel=slots-1;
    
        for(ballnum=1,column=0;balls>0;balls--,ballnum++,column++){
            if (column%5==0){
                printf("\n");
            }
            if (ballnum<10){
                printf("[0%d]",ballnum);
            }
            else{
                printf("[%d]",ballnum);
            }
            for(;tlevel>0;tlevel--){
                    r = rand() % 2;
                    if (r==0){
                        printf("R");
                    }
                    else {
                        printf("L");
                        lcounter++;
                    }
            }
            slotarry[lcounter]++;
            tlevel=slots-1;
            lcounter=0;
            printf("  ");
        }
        printf("\n\n%s",numbers);
        printf("%s",line);
    
        char line2[] = "\n +----+----+----+----+----+----+----+----+----+----+---+";
    
        for(;slotsduplicate<=slots;slotsduplicate++){
            if (slotsduplicate<10){
                printf("0%d|",slotsduplicate);
            }
            else{
                printf("%d|",slotsduplicate);
            }
            y=slotarry[slotsduplicate];
            if (y==0){
                printf(" 0");
            }
            else{
                for (;y>0;y--){
                    printf("#");
                }
                printf(" %d",slotarry[slotsduplicate]);
            }
            printf("%s",line2);
        }
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    Angry

    Manoj from m15202 please do your assignments by yourself. Furthermore just to highlight to everybody, this boy here took the code that he posted from this website Galton Box/Bean Machine-C - Stack Overflow. This is another persons work. This is considered as plagiarism. I kindly implore whoever who sees this post NOT to help the guy above. Thank you for your cooperation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming code help
    By stevesy in forum C Programming
    Replies: 4
    Last Post: 12-21-2014, 06:26 AM
  2. modification of C programming code.
    By engr_waqar290 in forum C Programming
    Replies: 7
    Last Post: 04-01-2013, 02:13 AM
  3. Help with programming code!!!
    By Manny01 in forum C Programming
    Replies: 3
    Last Post: 01-08-2012, 06:25 PM
  4. Does C++ be the code behind of DotNet programming for Web
    By rchiu5hk in forum C++ Programming
    Replies: 4
    Last Post: 09-03-2009, 06:10 AM

Tags for this Thread