Thread: Creating a program using print f

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    2

    Creating a program using print f

    These are the directions:

    1. Prompt the user to enter a character, an integer value (between 0 and 9), and a float value.
    2. Use printf formatting to print each value on its own line with the following specifications:
    a. All values should be right aligned 10 spaces from the left of the screen
    b. The integer should have 2 preceding zeros
    c. The float value should be printed with 3 decimal places

    This is what I have so far:

    Code:
    #include<stdio.h>
    
    int main(void)
    {
        char ch;
        int integer;
        float value;
    
    
        printf("Please enter a character:  ");
        scanf(" %c", &ch);
        printf("Please enter an integer value: ");
        scanf("%d", &integer );
        printf("Please enter a float value: ");
        scanf("%f", &value );
        printf("You Entered   \n%c\n%2d\n%7.2f");
    
        return 0;
    }
    I am having a problem figuring out how to print out the character and printing it out 10 spaces to the left of the screen.

  2. #2
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    The code things have to be all caps, there should be a button for it.

    But for your problem in the printf's just put 10 spaces in it like this...


    Code:
    printf("          You Entered \n%c\n%2d\n%7.2f");
    or you could make a loop for it every time so you don't have to put in 10 spaces.

    I hope this is what you mean and I hope it helps.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    2
    ok thank you..what about printing out a character? I'm not sure what I am doing wrong that makes it not print out.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You have to put variables after the format string in your printf statement to say which variables you want printed.

    Also it's [/code] not [\code].

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > The code things have to be all caps
    No it doesn't, but the \ has to be a / at the end.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 11:13 PM
  2. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  3. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  4. Creating a program within a program
    By GlitchGuy2 in forum C++ Programming
    Replies: 4
    Last Post: 09-11-2009, 10:53 PM
  5. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM

Tags for this Thread