C programming assignment

Discussion in 'C Programming' started by Illumin Arty, Sep 13, 2015.

  1. Illumin Arty

    Illumin Arty

    Joined:
    Sep 13, 2015
    Messages:
    1
    Likes Received:
    0
    Hi there!I am doing a assignment for college about the Galton Box in C.I made the code but there seems to be a bug.Please run the code below and help me by sending back the debugged code.Thanks!

    #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;
    }
     
    Illumin Arty, Sep 13, 2015
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Matt
    Replies:
    35
    Views:
    11,309
    George Neuner
    Jul 22, 2004
  2. chessc4c6
    Replies:
    9
    Views:
    736
    Old Wolf
    Mar 8, 2005
  3. janconway

    C Programming Assignment:

    janconway, Feb 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    6,812
    Malcolm
    Feb 24, 2004
  4. nagy
    Replies:
    36
    Views:
    1,639
    Terry Reedy
    Jul 20, 2006
  5. Casey Hawthorne
    Replies:
    4
    Views:
    1,434
    Jarek Zgoda
    Aug 4, 2006
  6. Chris
    Replies:
    34
    Views:
    2,558
  7. ajim
    Replies:
    3
    Views:
    433
  8. cppgm.org@gmail.com
    Replies:
    2
    Views:
    459
    Öö Tiib
    Feb 22, 2013
Loading...