beginer

Discussion in 'C' started by greenlazer, Sep 13, 2007.

  1. greenlazer

    greenlazer New Member

    Joined:
    Sep 13, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey everyone,
    I have just started to teach myself C, and i have been going through the exercises in this book and they have this script

    Code:
    #include <stdio.h>
    main()
    {
    	int age;
    	float weight;
    	char first[15], last[15];
    	
    	printf("\nWhat is your first name?");    /* A prompt*/
    	scanf(" %s", first);
    	printf("What is your last name?");
    	scanf(" %s", last);
    	
    	printf("How old are you? ");
    	scanf(" %d", &age);
    	printf("How much do you weigh? ");
    	scanf(" %f", &weight);
    	
    	printf("\nHere is the information you entered:\n");
    	printf("Name; %s %s\n", first, last);
    	printf("weight; %.0f\n", weight);
    	printf("Age; %d", age);
    	return 0; 
        
    }
    
    Now when i run the program it lets me enter all my information but it does not display the information i entered

    am i doing something wrong or is the book just missing a step

    thanks

    greenlazer
     
    Last edited by a moderator: Sep 13, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    First, you should read the "Before you make a query" thread BEFORE you make a query. That way you could put in your own code tags and I wouldn't have to be yo' mama and do it for you.

    Secondly, I suspect your program is working, but the window is closing before you see the output. This is normal. If you want to see your output, either run the program in a command window, or put a breakpoint at the "return 0", or put a statement such as "getchar ();" immediately before the return 0.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice