Thread: tables...

  1. #16
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    seperate your printf statement into 2 printf statements.. seperate them just after where you see the first \n. use this first statement to print the table 'headers' and 'footers', ie:

    printf("case\t....");

    for loop

    printf("case\t...");

    the equations arent programming specific, and they are related to your field, and also on the assignment website. declare some variables and give it a shot , post back your for loop.

  2. #17
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    my new problem...

    Code:
        fputs("case\t"  "voltage\t"  "Initial Resistance\t"  "Ending resistance\t"  "Increment Resistance\n", stdout);
    
        printf("%lf\t"  "%lf\t"      "%lf\t"                 "%lf\t"                "%lf\n", volts, init, ending, increment);
    
    
    return 0;
    
    }
    I have no way to line these up... depending on the size of the variables the tabs need to be altered.... is their another way?

    p.s. i'll go work on making a loop.

  3. #18
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    in place of using tabs (which don't always show up as tabs), use "%-10lf" for left-aligned 10 character output (with padded spaces).

    You now know that there are exactly 10 outputed chars.

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    i think i made it worse...
    Code:
    #include <stdio.h>
    #include <math.h>
    int main(void)
    
    {
    
    
        double volts, init, ending, increment, part=1;
        fputs("What is the voltage?", stdout);
          scanf("%lf", &volts);
        fputs("What is the initial resistance?", stdout);
          scanf("%lf", &init);
        fputs("What is the ending resistance?", stdout);
          scanf("%lf", &ending);
        fputs("What is the increment resistance?", stdout);
          scanf("%lf", &increment);
    
        fputs("case\t"  "voltage\t"  "Initial Resistance\t"  "Ending resistance\t"  "Increment Resistance\n", stdout);
    
        printf("lf"  "%-10lf"      "%-10lf"                 "%-10lf"                "%-10lf\n", part, volts, init, ending, increment);
    
        fputs("would you like to run the program again?", stdout);
        char r, y;  scanf("%i, &r");
    
    
        scanf("%i, &r");
        while (r = y)
    {
        double volts, init, ending, increment, part=1;
        fputs("What is the voltage?", stdout);
          scanf("%lf", &volts);
        fputs("What is the initial resistance?", stdout);
          scanf("%lf", &init);
        fputs("What is the ending resistance?", stdout);
          scanf("%lf", &ending);
        fputs("What is the increment resistance?", stdout);
          scanf("%lf", &increment);
    
        fputs("case\t"  "voltage\t"  "Initial Resistance\t"  "Ending resistance\t"  "Increment Resistance\n", stdout);
    
        printf("lf"  "%-10lf"      "%-10lf"                 "%-10lf"                "%-10lf\n", part, volts, init, ending, increment);
    
        fputs("would you like to run the program again?", stdout);
        char r, y;  scanf("%i, &r");
    
    ++r;
    }
    
    
    return 0;
    
    }
    Output:
    What is the voltage?1
    What is the initial resistance?2
    What is the ending resistance?3
    What is the increment resistance?4
    case voltage Initial Resistance Ending resistance Increment Resistance
    lf1.000000 1.000000 2.000000 3.000000
    would you like to run the program again?

    End output:

    if i type in any letter except n it reruns the program until i type ctrl c. whats wrong with my loop? and why didn't the spaces pad? thanks for the time.

  5. #20
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Well, I didn't mean to actually use that, just that was the format.

    Found this on the web. . . somewhere. It is handy to have for the print/scan f functions.

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    20
    well... if it's the right format then why did it not do anything? it doesn't space them at all=(

  7. #22
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    It wasn't the right format, just the format of the formatting. Consult the PDF for more information about formatting controls with printf.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ style tables
    By MarkZWEERS in forum C++ Programming
    Replies: 4
    Last Post: 05-18-2009, 08:41 AM
  2. Iterable hash tables
    By OnionKnight in forum Tech Board
    Replies: 5
    Last Post: 07-21-2008, 02:02 AM
  3. converting struct to tables in turbo c++
    By geft in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2008, 08:44 AM
  4. String tables in console apps
    By Sentral in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2006, 04:08 AM
  5. Help with beginning hash tables, please.
    By Will in forum C++ Programming
    Replies: 8
    Last Post: 11-17-2002, 09:51 PM