❔ Using WHILE to sum numbers from 10 until sum == 1000

Hello, how to make using function while () {} to make numbers from 10 to be sum until result is 1000 for example: 10 + 10 (first time) 20 + 11 (2th time) 31 + 12 (3rd time) 43 + 13 (4th time) and etc until result is 1000 also to print the last number after + my broken code:
int i = 10;
int a = 0;

while (i <= 1000)
{
a = a + i;
}

Console.WriteLine(a);
int i = 10;
int a = 0;

while (i <= 1000)
{
a = a + i;
}

Console.WriteLine(a);
2 Replies
peyzar2᲼᲼
peyzar2᲼᲼2y ago
so it has to start with 10 too? It is making the console empty. I need to cw only the last number which when you sum it makes 1000 yea i though the same tried adding i++ at the end but it makes some very big number So I need to make it to sum numbers after 10 and add after number is summed +1 like after 10 to sum the result before with 11 and the final result should be lower than 1000 I did mistake and typed = its only <. At the end it needs to console writeline the last number which was summed for example 35 to make the last number. This is more clear text. I managed to do it by 10+10 start, code is
int i = 10;
int a = 10;

while (a < 1000)
{
a += i++;
}

Console.WriteLine(a);
Console.WriteLine(i);
int i = 10;
int a = 10;

while (a < 1000)
{
a += i++;
}

Console.WriteLine(a);
Console.WriteLine(i);
but I need to start by 10+11 :/
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.