Thread: User determined input question

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Central Coast, California
    Posts
    9

    User determined input question

    Hi, I am writing a program that requires user determined input at the beginning of the program. I must ask the user to input a number that will determine the number of integers that the user will put in later. My question is, how do you specify in the program to take that number entered in implement it later so when they are entering integers, it won't allow any more than they already specified.

    Code:
     
    #include <stdio.h>
    
    int main (void)
    {
    	int num;
    	double fah;
    	double cel;
    	
    	printf ("Please enter the number of temperatures you will be entering:\n\n ");
    	scanf ("%i", &num);
    	while ( (num < 1) || (num > 25) )
    	{
    		printf ("The value you entered is out of range, please input a value between 1 and 25:\n\n ");
    		scanf ("%i", &num);
    	}
    	
    	printf ("Now input your %i Fahrenheit temperature values:\n\n ", num);
    	scanf ("%lf", &fah);
    	while ( (fah < -125.0) || (fah > 125.0) )
    	{
    		printf ("%.1lf is out of range, please input a value between -125.0 and 125.0:\n\n ", fah);
    		scanf ("%lf", &fah);
    	}
    
    	return 0;
    }
    That is all I have so far. Later in the program I also have to use the numbers inputed to calculate averages and the like.

    Any thoughts?

    Thank you.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by lyoncourt View Post
    My question is, how do you specify in the program to take that number entered in implement it later so when they are entering integers, it won't allow any more than they already specified.
    Save their original value in variable, and use it later in a condition.

    If I'm not understanding the question, clarify the question and try asking again.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Location
    Central Coast, California
    Posts
    9
    I am not exactly sure what or how to do it, hence the confusion on my part. Let me try to explain again.

    User will input a value that will indicate how many values they intend to enter later. Let's say 4. So then the use is expected now to enter 4 numbers; let's say 12, 15, 18, 22.

    Now those four numbers must be used to create an average, high, low, etc etc.

    So what I am wondering is how to tell the program to expect those four numbers and nothing more, and then how to I label those four numbers (or more or less) to use later in figuring averages and what not.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    OK, then my answer is exactly what it was before. Save the original number somewhere in some variable.... call it limit.

    Once you have that, you can create a condition:

    Code:
    for(i=0;i<limit;i++)
    {
    	/* read in a number and do calculations here */
    }
    This will perform the loop 4 times.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Location
    Central Coast, California
    Posts
    9
    I'm sorry MacGyver, you have been so helpful yet I am simply not understanding what to do. I am so new to this.

    Thank you though.

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Mmkay, soooooooooo....

    Tell me what part you don't get, and let's go from there.

    Incidentally, did you even write the code you posted? Since you cannot understand the loop I wrote or the concept I'm trying to get across, I suspect you got the original code from somewhere else. It's possible I'm just so tired that I'm typing in gibberish, but I still suspect something is wrong on your end as well.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Location
    Central Coast, California
    Posts
    9
    No, I actually did write this code :/ I just started learning loops and stuff so I'm still trying to catch on to it.

    Nevermind.

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    So then what's the problem understanding my post? If you can't spit the question out, I can't give you the answer. Basic I/O issues here! lol....

  9. #9
    Registered User
    Join Date
    Sep 2007
    Location
    Central Coast, California
    Posts
    9
    I gave you my question and you gave me your answer and I am still trying to understand and figure things out. It's as simple as that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. timed user input
    By sainiabhishek in forum C Programming
    Replies: 4
    Last Post: 04-01-2009, 11:59 AM
  2. Truncating user input
    By CS_Student8337 in forum C Programming
    Replies: 10
    Last Post: 03-19-2009, 12:34 AM
  3. Defining classes following user input. Inheritance.
    By Swerve in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2009, 09:21 AM
  4. Ending user input with # character
    By jowatkins in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2004, 10:41 AM
  5. Replies: 4
    Last Post: 04-21-2004, 04:18 PM