C# Homework - control structures (for, if)
Posted
by
Freakingout
on Stack Overflow
See other posts from Stack Overflow
or by Freakingout
Published on 2009-02-23T18:39:26Z
Indexed on
2012/06/17
15:16 UTC
Read the original article
Hit count: 225
I got a homework assignment today: "Create a program that calculates out how many ways you can add three numbers so that they equal 1000."
I think this code should work, but it doesn't write out anything.
using System;
namespace ConsoleApp02
{
class Program
{
public static void Main(string[] args)
{
for(int a = 0; a < 1000; a++)
{
for(int b = 0; b < 1000; b++)
{
for(int c = 0; c < 1000; c++)
{
for(int puls = a + b + c; puls < 1000; puls++)
{
if(puls == 1000)
{
Console.WriteLine("{0} + {1} + {2} = 1000", a, b, c);
}
}
}
}
}
Console.ReadKey(true);
}
}
}
What am I doing wrong? Any tips or solution?
© Stack Overflow or respective owner