Song Lee

Song Lee

  • NA
  • 47
  • 38.7k

Program that sums up whole numbers

Sep 23 2014 9:53 AM
Hello C# Corner members,
I have to write a program that sums up whole numbers with loop function.
 
So it needs to do these:
1. ask the user for how many whole numbers to add
2. lets the user give the numbers. Read each of the numbers into the program.
3.sum up the numbers and show the results.
 
Here is the visual of what it should look like (The orange writings input by user) :
 ----------------------------------------------------------------------------------------------------------------------------------
 
******Summation of whole numbers***********
 
Number of  values to sum? : 3
 
Please give the value #1(whole number) : 500
Please give the value #2(whole number) : -250
Please give the value #3(whole number) : 150
--------------------------------------------------------------
The sum is 400 
 
------------------------------------------------------------------------------------------------------------------------------------ 
 
So far, I have these:
 
 
private int numOfInput;
private int sum;
public void Start()
{
            WriteProgramInfo();
            ReadInput();
            SumNumbers();
            ShowResults();
}
private void ReadInput()
{
            Console.Write("Number of values to sum? ");
            numOfInput = int.Parse(Console.ReadLine());
            Console.WriteLine(); }
      private void WriteProgramInfo()
{
Console.WriteLine("\n\n <<Summation of Whole Numbers>>");
Console.WriteLine(" Using a for-statement\n");
Console.WriteLine();
}
private void SumNumbers()
{
         int index;
         int num = 0;
         for (index = 0; index < numOfInput; index++)
 
{//Calculation part here I Think?
}}
private void ShowResults()
{
         Console.WriteLine("---------------------------\n");
         Console.WriteLine("The sum is \t{0}", sum);
}
}
}
 

Answers (3)