How to display this using MessageBox.Show method

A

Amanda

Can anyone help me to display the output in MessageBox for the
following program result?
--------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace A2_CISP40506F
{
class A2
{

static void Main(string[] args)
{
double p = 1000;
double r = .05, interest = 0;
double a = 0;
Console.WriteLine("Year\tAmount On Deposit\tInterest");
for (int year = 1; year <= 100; year++)
{
interest += a * r;
a = p + a * (1 + r);
Console.WriteLine("{0}\t{1:C}\t\t{2:C}", year, a,
interest);

}
}
} // class A2
}
 
M

Michael A. Covington

I think what you want is:

MessageBox.Show(String.Format("{0}\t{1:C}\t\t{2:C}", year, a, interest));

In general, String.Format does the same kind of formatting as WriteLine, but
the result is returned as a string (which you can then output any way you
want) rather than being written on the console.
 
A

Amanda

Michael said:
I think what you want is:

MessageBox.Show(String.Format("{0}\t{1:C}\t\t{2:C}", year, a, interest));

Yes, I couldn't use MessageBox.show because I cteated the project as
console. I fixed that.

And, I do not want the title of messagebox repeated. So I concatenated
the string and then call MessageBox.Show outside the for loop.
 
F

Forrest

Uzytkownik "Amanda said:
Yes, I couldn't use MessageBox.show because I cteated the project as
console. I fixed that.

And, I do not want the title of messagebox repeated. So I concatenated
the string and then call MessageBox.Show outside the for loop.

Try add using System.Windows.Forms it help

Forrest
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top