Thread: help with array and reminder.

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    13

    help with array and reminder.

    hi guys. 2 quick questions!

    1st:

    i want to make a simple array that is unlimited and that takes all the numbers u put in it and prints the summary of em.


    2nd:

    how do i print the wggs that dont fit in the Containers? lets say i type in 28eggs. then i want to print :

    you have; 28eggs
    you need 2 containers
    you have 4 eggs left.
    fought i should use %reminder but didnt seem to get it to work


    Code:
    #include <stdio.h>
    void main()
    { int iEgg, iContainer ,iLeft;
    
    printf("type your amount of eggs: ");
    scanf("%d", &iEgg);
    ikartonger = iEgg / 12;
    
    
    printf("you have: %d  Eggs\n", iEgg);
    printf("you need: = %d containers\n",  iContainer);
    
    
    iLeft =   ;
    printf("you have: = %d eggs left\n", iLeft);
     }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    #include <stdio.h>
    
    void main()
    { int iEgg, iContainer ,iLeft;
    
    printf("type your amount of eggs: ");
    scanf("%d", &iEgg);
    ikartonger = iEgg / 12;
    
    
    printf("you have: %d  Eggs\n", iEgg);
    printf("you need: = %d containers\n",  iContainer);
    
    
    iLeft =   ;
    printf("you have: = %d eggs left\n", iLeft);
     }
    
    //c'mon Casper! You left "iLeft being assigned the value of <nothing>!!
    
    
    iLeft = iEgg  - (iContainer * number in each container)
    
    or
    
    iLeft = iEgg % (iContainer * number in each container)
    There's no such thing as "unlimited" in your computer. Everything is finite, especially arrays and RAM.

    Printing up a summary should be no problem with any array. What have you tried ?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by Adak View Post
    Code:
    #include <stdio.h>
    
    void main()
    { int iEgg, iContainer ,iLeft;
    
    printf("type your amount of eggs: ");
    scanf("%d", &iEgg);
    ikartonger = iEgg / 12;
    
    
    printf("you have: %d  Eggs\n", iEgg);
    printf("you need: = %d containers\n",  iContainer);
    
    
    iLeft =   ;
    printf("you have: = %d eggs left\n", iLeft);
     }
    
    //c'mon Casper! You left "iLeft being assigned the value of <nothing>!!
    
    
    iLeft = iEgg  - (iContainer * number in each container)
    
    or
    
    iLeft = iEgg % (iContainer * number in each container)
    There's no such thing as "unlimited" in your computer. Everything is finite, especially arrays and RAM.

    Printing up a summary should be no problem with any array. What have you tried ?

    yeah i did leave it empty, beacuse i dint know what to type

    i dont understand what u mean with :

    iLeft = iEgg - (iContainer * number in each container)

    or

    iLeft = iEgg % (iContainer * number in each container)

    i did try to print the eggs that didnt fit in the containers by trying this code:

    Code:
    iLeft =   iEgg % Container
    but it dint work..

    the funny thing is when i try to use %reminder with nummbers it gives med the right answer. Like 17%5 = 2..



    to be honest i think my brain is taking a break atm, becuse i cant think at all. cant get the structure at all...



    this is my "unlimited array code so far:

    Code:
     #include <stdio.h>
    void main()
    {
    
    int iNumber[];
    int sum;
    for (int i=0;i<10; i++)
    {
    
    printf("put in numbers: ");
    scanf("%d", &iNumber[i]);
    sum += iNumber[i];
    }
    printf("%d", sum);
    
    }
    The fought is to make it work so that u can type in numbers until u press any other key, then the program take all the numbers and prints the sum of em.
    Last edited by casper87; 10-31-2009 at 04:30 AM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Say you had 26 eggs:

    You fill two containers, which each hold 12 eggs.

    that would be 2 * 12 (containers * number each container holds)

    Which totals to 24 eggs in containers.

    Left over eggs = original number of eggs - eggs you put into containers, or

    left over eggs = 26 - 24

    left over eggs = 2

    Which is a long way around to this answer:

    left over eggs = 26 - (2 * 12)

    You can't create an array with no size, unless you give the compiler a number it can could up for you. for instance, this is OK:

    Code:
    char myString[] = { "My Grandfather's clock was too large for the shelf, so it stood 90 years on the floor" };
    And you don't have to count up all the char's for the array's size, the compiler will do it for you.

    But if you just have
    char myString[]

    You have an array with no space, and should have a compiler warning at least.

    If you put the above phrase into it, it should crash the program, before long.
    Last edited by Adak; 10-31-2009 at 05:31 AM.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by Adak View Post
    Say you had 26 eggs:

    You fill two containers, which each hold 12 eggs.

    that would be 2 * 12 (containers * number each container holds)

    Which totals to 24 eggs in containers.

    Left over eggs = original number of eggs - eggs you put into containers, or

    left over eggs = 26 - 24

    left over eggs = 2

    Which is a long way around to this answer:

    left over eggs = 26 - (2 * 12)

    You can't create an array with no size, unless you give the compiler a number it can could up for you. for instance, this is OK:

    Code:
    char myString[] = { "My Grandfather's clock was too large for the shelf, so it stood 90 years on the floor" };
    And you don't have to count up all the char's for the array's size, the compiler will do it for you.

    But if you just have
    char myString[]

    You have an array with no space, and should have a compiler warning at least.

    If you put the above phrase into it, it should crash the program, before long.

    think i sorted it out

    Code:
    #include <stdio.h>
    
    void main()
    { int iEgg, iContainer ,iLeft , iSpace , iContainerhold;
    
    printf("type your amount of eggs: ");
    scanf("%d", &iEgg);
    iSpace =12;
    iContainerhold = iSpace;
    iContainer =iEgg/iContainerhold;
    
    
    
    
    
    printf("you have: %d  Eggs\n", iEgg);
    printf("you need: = %d containers\n",  iContainer);
    
    
    iLeft = iEgg - (iContainer* iContainerhold);
    printf("you have: = %d eggs left\n", iLeft);
     }

    u think u could code the unlimited" code for me? i reallt cant think right now..
    Last edited by casper87; 10-31-2009 at 05:57 AM.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Nope, because

    1) I'm off for some breakfast and

    2) You have it done, already. Give the array a size, and I believe you're set.

    3) When you're ready, you need the practice. Programming is not a spectator sport, you have to really work at it.

    Like most things, I guess.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. example from c programming "a modern approach"
    By convenientstore in forum C Programming
    Replies: 8
    Last Post: 06-15-2009, 03:08 AM
  2. Error passing an array of structs
    By Catalyst8487 in forum C++ Programming
    Replies: 10
    Last Post: 12-15-2008, 03:38 PM
  3. Placing array in temp table
    By cjohnman in forum C Programming
    Replies: 3
    Last Post: 04-16-2008, 12:53 PM
  4. how do i calculate prime number
    By pimp in forum C Programming
    Replies: 50
    Last Post: 01-12-2008, 10:25 PM