section three... correct?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vinnie

    #1

    section three... correct?

    I have made my first class wih function, trying to calculate the
    interest paied on a principal. It works until reach the endo f section
    2. Section 3 that supposed to print out the results, it does not work.
    I don;t get any error msg but i don't get either the results. Why?

    namespace TassoIntereste

    {
    public class Program
    {
    public static void Main(string[] args)
    {

    // - SECTION 1 -
    decimal Capitale_Inizia le = 0;
    decimal Interesse = 0;
    decimal Anni = 0;

    InserimentoDati (ref Capitale_Inizia le, ref Interesse, ref
    Anni);

    // - SECTION 2 -
    Console.WriteLi ne(); // riga vuota
    Console.WriteLi ne(" Capitale = " + Capitale_Inizia le);
    Console.WriteLi ne(" Intersse = " + Interesse + "%");
    Console.WriteLi ne(" Durata = " + Anni + " Anni");
    Console.WriteLi ne(); // riga vuota

    // - SECTION 3 -
    Console.WriteLi ne("Premi un tasto per terminare il
    programma... ");
    Console.Read();
    }

    // Implement section 1.
    public static void InserimentoDati (ref decimal
    Capitale_Inizia le, ref decimal Interesse, ref decimal Anni)
    {
    // 1A - Immissione del Capitale
    Capitale_Inizia le = Inserimento_Dat i("Capitale") ;

    // 1B - Inserimento tasso di interesse
    Interesse = Inserimento_Dat i("Interesse" );

    // 1C - La durata
    Anni = Inserimento_Dat i("Anni");
    }


    public static decimal Inserimento_Dat i(string Immissione)
    {

    while (true)
    {
    Console.WriteLi ne(" Inserisci " + Immissione + ":");
    string Inserito = Console.ReadLin e();
    decimal Valore_Immesso = Convert.ToDecim al(Inserito);

    if (Valore_Immesso >= 0)
    {
    return Valore_Immesso;
    }

    else
    {
    Console.WriteLi ne(Immissione + " non puo' essere
    negativo");
    Console.WriteLi ne(" Riprova... ");
    Console.WriteLi ne();
    }
    }
    }


    // Implement SECTION 3 -
    public void Calcolo_Tabella (ref decimal Capitale_Inizia le, ref
    decimal Interesse, ref decimal Anni)
    {
    for (int i = 1; i<= Anni; i++)
    {

    decimal interesse_pagat o = (Capitale_Inizi ale *
    (Interesse / 100));


    Capitale_Inizia le = Capitale_Inizia le +
    interesse_pagat o;


    Capitale_Inizia le = decimal.Round(C apitale_Inizial e,
    2);


    Console.WriteLi ne(i + "-" + Capitale_Inizia le);
    }
    }

    }
    }

  • Paul E Collins

    #2
    Re: section three... correct?

    "vinnie" <centro.gamma@g mail.comwrote:
    I don;t get any error msg but i don't get either the results. Why?
    Your code never calls the Calcolo_Tabella method.

    Eq.


    Comment

    • Morten Wennevik [C# MVP]

      #3
      Re: section three... correct?

      On Sat, 01 Sep 2007 19:13:53 +0200, vinnie <centro.gamma@g mail.comwrote:
      I have made my first class wih function, trying to calculate the
      interest paied on a principal. It works until reach the endo f section
      2. Section 3 that supposed to print out the results, it does not work.
      I don;t get any error msg but i don't get either the results. Why?
      >
      namespace TassoIntereste
      >
      {
      public class Program
      {
      public static void Main(string[] args)
      {
      >
      // - SECTION 1 -
      decimal Capitale_Inizia le = 0;
      decimal Interesse = 0;
      decimal Anni = 0;
      >
      InserimentoDati (ref Capitale_Inizia le, ref Interesse, ref
      Anni);
      >
      // - SECTION 2 -
      Console.WriteLi ne(); // riga vuota
      Console.WriteLi ne(" Capitale = " + Capitale_Inizia le);
      Console.WriteLi ne(" Intersse = " + Interesse + "%");
      Console.WriteLi ne(" Durata = " + Anni + " Anni");
      Console.WriteLi ne(); // riga vuota
      >
      // - SECTION 3 -
      Console.WriteLi ne("Premi un tasto per terminare il
      programma... ");
      Console.Read();
      }
      >
      // Implement section 1.
      public static void InserimentoDati (ref decimal
      Capitale_Inizia le, ref decimal Interesse, ref decimal Anni)
      {
      // 1A - Immissione del Capitale
      Capitale_Inizia le = Inserimento_Dat i("Capitale") ;
      >
      // 1B - Inserimento tasso di interesse
      Interesse = Inserimento_Dat i("Interesse" );
      >
      // 1C - La durata
      Anni = Inserimento_Dat i("Anni");
      }
      >
      >
      public static decimal Inserimento_Dat i(string Immissione)
      {
      >
      while (true)
      {
      Console.WriteLi ne(" Inserisci " + Immissione + ":");
      string Inserito = Console.ReadLin e();
      decimal Valore_Immesso = Convert.ToDecim al(Inserito);
      >
      if (Valore_Immesso >= 0)
      {
      return Valore_Immesso;
      }
      >
      else
      {
      Console.WriteLi ne(Immissione + " non puo' essere
      negativo");
      Console.WriteLi ne(" Riprova... ");
      Console.WriteLi ne();
      }
      }
      }
      >
      >
      // Implement SECTION 3 -
      public void Calcolo_Tabella (ref decimal Capitale_Inizia le, ref
      decimal Interesse, ref decimal Anni)
      {
      for (int i = 1; i<= Anni; i++)
      {
      >
      decimal interesse_pagat o = (Capitale_Inizi ale *
      (Interesse / 100));
      >
      >
      Capitale_Inizia le = Capitale_Inizia le +
      interesse_pagat o;
      >
      >
      Capitale_Inizia le = decimal.Round(C apitale_Inizial e,
      2);
      >
      >
      Console.WriteLi ne(i + "-" + Capitale_Inizia le);
      }
      }
      >
      }
      }
      >
      >
      Hi Vinnie,

      This looks like a school work assignment, and I won't give you the answer other than point out that although Section 3 isn't outputting the answer, take a closer look at some code marked Section 3 later in your sample. If you still have problems, please free to ask again.

      --
      Happy coding!
      Morten Wennevik [C# MVP]

      Comment

      • vinnie

        #4
        Re: section three... correct?

        On Sep 1, 1:30 pm, "Paul E Collins" <find_my_real_a ddr...@CL4.org>
        wrote:
        >
        Your code never calls the Calcolo_Tabella method.
        >
        Eq.
        Thanks lot: i understood my error, i corrected it, and i made myself
        really happy!!!

        hopefully one day i'll be as good as you all!

        Comment

        Working...