0

hello, im trying to display a header in my output and have looked at a code from an example in my book but added a few more variables to it. The book only has two but I have five and after I changed the example to include all my five it only shows the first two.

here is the part of my code

// display headers
         Console.WriteLine("Year{0, 20}", "Rate",  "Amount", "Interest", "New Amount");

this is the output it shows
Year Rate

but i want it to show

Year Rate Amount Interest New Amount

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jonsca
1

The {0,20} is a placeholder and format specifier for a variable that was in the other example you had. For example:

int i = 1;
char a = 'a';
double pi = 3.14159;
Console.WriteLine("{0} {1} {2}",i,a,pi);

prints out: 1 a 3.14145 (each placeholder is replaced by the value)

So for your application, you can just simply make it one string: Console.WriteLine("Year Rate Amount Interest New Amount"); or if you want the year in there Console.WriteLine("Year {0} Rate Amount Interest New Amount",year);

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.