- #1
adjacent
Gold Member
- 1,552
- 63
I am writing this in C#. Here is the code.
Problems;
Code:
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
int uservalue;
Int32.TryParse(Console.ReadLine(),out uservalue);
for (int i = 0;i <= uservalue;i++)
{
sum += i;
}
Console.WriteLine("Sum of the Natural numbers from 0 to {1} is:{0}",sum,uservalue);
Console.ReadLine();
Console.ReadLine();
}
}
}
- If I write 100 in the console, it assumes that I wrote 57
- How do I make it possible for the user to write and calculate the sum as much as he/she wants? I wrote two Console.ReadLines there. So it allows me to write only one number, after getting that string, if I write another number, the console closes
Last edited: