How to display this using MessageBox.Show method

  • Thread starter Thread starter Amanda
  • Start date Start date
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
}
 
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.
 
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.
 
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
 
Back
Top