Thread: C program does not take input from user

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    12

    Question C program does not take input from user

    Error of uninitialized variable for value and number shows up. Why can I not enter those numbers?
    insert
    Code:
    1. #include<stdio.h>
    2. int main()
    3. {
    4. int i, value, sum = 0, number;
    5. printf("Enter the number of integers to be entered:");
    6. scanf_s("%d", number);
    7. for (i = 1; i <= number; i++)
    8. {
    9. printf("Enter a value", value);
    10. scanf_s("%d", &value);
    11. sum += i;
    12. printf("The sum is %d", sum);
    13. }
    14. }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > scanf_s("%d", number);
    What is missing here.

    > scanf_s("%d", &value);
    That is present here.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    12
    Oh ok, I entered ampersand and the error for number vanished but uninitialization error for value still remains.
    Last edited by Izzy98; 11-06-2015 at 03:06 PM.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Code:
    printf("Enter a value", value);
    scanf_s("%d", &value);
    When do you put a value in "value". When do you use that value? See any problem?

  5. #5
    Registered User
    Join Date
    Nov 2015
    Posts
    12
    Yes now I realize my mistake. This code works, thank you very much all!
    insert
    Code:
    #include<stdio.h>
    int main()
    {
    	int i, value, sum = 0, number;
    	printf("Enter the number of integers to be entered:");
    	scanf_s("%d", &number);
    	for (i = 1 ; i <= number; i++)
    	{
    		printf("Enter a value");
    		scanf_s("%d", &value);
    		sum += value;
    	}
    	printf("The sum is %d", sum);
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with addition program with user input
    By icyinfernoz in forum C Programming
    Replies: 4
    Last Post: 09-07-2014, 03:54 PM
  2. Replies: 6
    Last Post: 10-26-2013, 02:48 PM
  3. Want User Input but Program Ends
    By completenewbieu in forum C Programming
    Replies: 5
    Last Post: 08-29-2011, 04:10 PM
  4. Replies: 3
    Last Post: 10-12-2010, 01:40 PM
  5. user input and program design
    By Chaplin27 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2005, 08:53 AM

Tags for this Thread