nested loops

This is a discussion on nested loops within the C Programming forums, part of the General Programming Boards category; write a c program that asks the user how many results there are per experiment then, using a nested loop, ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    nested loops

    write a c program that asks the user how many results there are per experiment then, using a nested loop, ask the user to enter the results for all four experiments.....
    Here is what i have so far. i can't get the experiment value included in the loop. CAN U PLEASE HELP?
    but i can get the number of results

    Code:
    #include<stdio.h>
    
    int main()
    {
    	int num_results,i,j;
    	float exp_value, total, average;
    
    	printf("Please enter the number of results per experiment:");
    	scanf("%d",&num_results);
    	
    	for( i=1 ;i<=num_results ;++i )
    	
    	{		
    	printf("Please enter result %d for experiment %d\n",i,j);
    	
    	}
    
    	return (0);	
    }

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    *yoink* *Saves kermi3 some work and adds code tags to code*

    I'm not really understanding your question (maybe I'm slow). Whats your problem really? Why arent you using scanf to get input from the user inside that for loop?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    u missed the include for a tag L@D

    what do u mean u can't get it int he loop? its "in" the loop now, do u mean its not executing? And what compiler are you useing?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>write a c program
    ... and you've failed at the first hurdle... this is the C++ board. Hang on tight, we'll move you over to the C board.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    no wonder VSC++ was *****ing at me

  6. #6
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>u missed the include for a tag L@D

    Oops, fixed. Guess I'm not as good at this as kermi.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>using a nested loop
    ... means you need one loop inside another. Like this :
    Code:
    for i=0 to MaxExperiments
        print Getting Result For Experient Number $i
        for j=0 to MaxResults
            print Please enter result number $j
            ReadAndStoreInput
        endfor
    endfor
    I presume you're supposed to store the results in a 2d array? I haven't shown that in my pseudo code though, but the basics is there for you to expand upon.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested loops
    By zeondik in forum C# Programming
    Replies: 2
    Last Post: 10-26-2008, 07:58 AM
  2. Nested For Loops
    By smitsky in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2004, 01:58 PM
  3. Evaluation of nested loops
    By Mister C in forum C Programming
    Replies: 2
    Last Post: 08-13-2004, 02:47 PM
  4. nested for loops
    By akub3 in forum C Programming
    Replies: 2
    Last Post: 04-01-2004, 06:21 AM
  5. Nested for loops
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2002, 10:25 AM

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