Basic Start up

This is a discussion on Basic Start up within the C Programming forums, part of the General Programming Boards category; i can't find any examples in my book (and yes its for my project but i only want to know ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    8

    Basic Start up

    i can't find any examples in my book (and yes its for my project but i only want to know the simplest way to input numbers into an array)

    I want the output to go along the lines of

    . Week1
    . Day 1: (the user inputs number)
    . Day 2: (the user inputs number)
    . Day 3: (the user inputs number)
    . Day 4: (the user inputs number)
    . Day 5: (the user inputs number)
    . Day 6: (the user inputs number)
    . Day 7: (the user inputs number)

    Week 2 .... so on

    Therefore making a 7 by j array allowing j to be any number
    Code:
    #include <stdio.h>
    
    int j=0;
    int i=7;
    int choc_[7][100];
    
    
    
    
    int main()
    {
    int w,d,q;
    printf ("How many weeks would you like the program to run?\n");
    scanf ("%d",&j);
    	{
            
            for ( w=1; w<=j; w++)
            {
            printf ("\t Week %d \n",w);
             	 for ( d=1; d<=i; d++) 
             	 printf ("\t\tDay %d:\n",d); 
                      	scanf ("%d", &q); 
                       }
                       }
                       }
    i know this is basic, but i have had to teach myself this and i can't seem to find any examples in books or on-line
    thanks for your time
    Last edited by qweqwe; 12-04-2011 at 09:28 AM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    You already have the array indexes in your iterator variables. Remember that array indexers are 0-based:
    Code:
    for(w = 0;w < j;w++)
    {
      printf("\t week %d \n", w + 1); // Since w starts at 0 now, make it print as if 1 was the first index
      for(d = 0;d < 7;d++) // i seems unnecessary and just confusing. Every week has 7 days and i is a horrible name for this
      {
        printf("\t\tDay %d: ", d + 1); // Again, d starts at 0 now, but make it print pretty
        scanf("%d", &choc_[d][w]);
      }
    }
    I'd recommend getting out of the habit of using meaningless variable names. It'll just lead to trouble.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    8
    Thanks for that

    If i wished to print out the array into a text file would i have to put spaces between the numbers and insert new lines when i want the row to finish? .. just a bit confused on that

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    No, we have a "space" fairy, and also a "newline" fairy, that magically sprinkle their sparkling dust, on all C output! < ROFL! >

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by qweqwe View Post
    Thanks for that

    If i wished to print out the array into a text file would i have to put spaces between the numbers and insert new lines when i want the row to finish? .. just a bit confused on that
    Just like you were typing it by hand....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best Way To Start
    By nathanpc in forum C++ Programming
    Replies: 18
    Last Post: 07-12-2009, 09:25 AM
  2. were do i start
    By diving in in forum Game Programming
    Replies: 14
    Last Post: 01-27-2006, 07:37 PM
  3. Where to start?
    By sreetvert83 in forum Windows Programming
    Replies: 5
    Last Post: 07-25-2005, 10:02 PM
  4. C++ help: Don't know where to start
    By firestorm in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2005, 07:39 PM
  5. Don't even know where to start.... do while...
    By thynksheraze in forum C++ Programming
    Replies: 6
    Last Post: 02-05-2003, 05:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21