I'm looking at this, but the first thing I see is a typo on line 44 (the semi-colon).
Also the closing brace on 19 needs to be moved to 47 or 49.
Also, C# is case-sensitive, so your numOfInPut should match the case of NumOfInPut.
...and if this was meant to be the main module of a console app, you're missing Main().
Did you accidentally delete it?
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Your code seems to be all messed up.
You got to use an Array or better a List to store your inputted numbers
Write an input loop for that.
Then loop trough your array or list and sum all the numbers.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Console.ReadLine()
...then convert the result to a numeric type like an integer
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Yes, just put it next to it.
Are you using Visual Studio to edit your code?
using System;
namespace DW_409292_CS2_CON
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
string strData = Console.ReadLine().Trim();
int intData = 0;
if (!int.TryParse(strData, out intData))
{
Console.WriteLine("Invalid number: " + strData);
return;
}
Console.WriteLine(intData.ToString() + " is a nice number");
}
}
}
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class WholeNumbersFor
{
private int numOfInPut = 0;
private int sum = 0;
public void start()
{
WriteProgramInfo();
ReadInPut();
SumNumbers();
ShowResults();
}
private void ReadInPut()
{
Console.Write("Number of Values to sum?");
try
{
numOfInPut = int.Parse(Console.ReadLine().Trim());
}
catch
{
Console.WriteLine("Enter valid number");
}
Console.WriteLine();
}
private void WriteProgramInfo()
{
Console.WriteLine("\n\n ++++++ Summation of whole numbers ++++++");
Console.WriteLine();
}
private void SumNumbers()
{
int index;
int temp = 0;
for (index = 0; index < numOfInPut; index++)
{
try
{
Console.WriteLine("Enter the" + index.ToString() + "th Value");
temp = int.Parse(Console.ReadLine().Trim());
if (temp == 0)
{
index--;
}
else
{
sum += temp;
}
}
catch
{
Console.WriteLine("enter Valid integer");
index--;
}
}
}
private void ShowResults()
{
Console.WriteLine("\n\n ++++++ Summation of whole numbers is"+ sum.ToString() +" ++++++");
Console.WriteLine();
}
}
}
mani-hellboy
Junior Poster in Training
69 posts since Feb 2012
Reputation Points: 0
Solved Threads: 7