section three... correct?

V

vinnie

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_Iniziale = 0;
decimal Interesse = 0;
decimal Anni = 0;

InserimentoDati(ref Capitale_Iniziale, ref Interesse, ref
Anni);

// - SECTION 2 -
Console.WriteLine(); // riga vuota
Console.WriteLine(" Capitale = " + Capitale_Iniziale);
Console.WriteLine(" Intersse = " + Interesse + "%");
Console.WriteLine(" Durata = " + Anni + " Anni");
Console.WriteLine(); // riga vuota

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

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

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

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


public static decimal Inserimento_Dati(string Immissione)
{

while (true)
{
Console.WriteLine(" Inserisci " + Immissione + ":");
string Inserito = Console.ReadLine();
decimal Valore_Immesso = Convert.ToDecimal(Inserito);

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

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


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

decimal interesse_pagato = (Capitale_Iniziale *
(Interesse / 100));


Capitale_Iniziale = Capitale_Iniziale +
interesse_pagato;


Capitale_Iniziale = decimal.Round(Capitale_Iniziale,
2);


Console.WriteLine(i + "-" + Capitale_Iniziale);
}
}

}
}
 
M

Morten Wennevik [C# MVP]

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_Iniziale = 0;
decimal Interesse = 0;
decimal Anni = 0;

InserimentoDati(ref Capitale_Iniziale, ref Interesse, ref
Anni);

// - SECTION 2 -
Console.WriteLine(); // riga vuota
Console.WriteLine(" Capitale = " + Capitale_Iniziale);
Console.WriteLine(" Intersse = " + Interesse + "%");
Console.WriteLine(" Durata = " + Anni + " Anni");
Console.WriteLine(); // riga vuota

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

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

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

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


public static decimal Inserimento_Dati(string Immissione)
{

while (true)
{
Console.WriteLine(" Inserisci " + Immissione + ":");
string Inserito = Console.ReadLine();
decimal Valore_Immesso = Convert.ToDecimal(Inserito);

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

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


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

decimal interesse_pagato = (Capitale_Iniziale *
(Interesse / 100));


Capitale_Iniziale = Capitale_Iniziale +
interesse_pagato;


Capitale_Iniziale = decimal.Round(Capitale_Iniziale,
2);


Console.WriteLine(i + "-" + Capitale_Iniziale);
}
}

}
}

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.
 
V

vinnie

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!
 

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

Similar Threads

magic code.... 6
so long? no other way? 11
why this msg? 5
DHCP with P/Invoke 5
MSDN C# example on IPCChannel compile error ! 2
Boxed Value Types 2
Help with SetupInstallFromInfSection 3
Strange behaviour 10

Top