Can someone help me with this, having trouble with loops. I need to write a program that prints every integer value from 1 to 20, along with its squared value. Thanks for any assistance.

Recommended Answers

All 5 Replies

Can someone help me with this, having trouble with loops. I need to write a program that prints every integer value from 1 to 20, along with its squared value. Thanks for any assistance.

What type of problem are you having? Can you not figure out the logic or do you simply not know enough about loops?

There are many looping structures out there. There's while, do, foreach, for, etc. Have you ever used them? But the loop you're mostly likely going to use for this is the for loop. Providing an example would probably constitute doing most of your homework for you, so I would suggest looking it up on MSDN or, more likely, in a textbook that is used in your class.

Can you write a program that prints out every value from 1 to 20? What type of loop are you thinking of using? With those questions in mind, try something out first and post your code and we can help you with it.

EDIT: Well apegram edged me out by a 1/4 second.

for(int i = 1; i <= 20; i++)
{
  Console.WriteLine(i + " squared is " + i*i);
}

koekoeksklok, please read the daniweb forum policy regarding homework help. Whilst it may seem somewhat convoluted; not giving him the code was the best kind of help you could have given him.
By giving him the code, you have deprived him of the learning opportunity he faced if he solved it himself.

@Cardinals1980, i seriously advise that you do the reading required even though you now have a solution. If you don't understand the fundamentals you will come severely unstuck when you try to work with the more complex coding paradigms. The best way to learn to code is to read a lot and experiment more. The MSDN website has an exhaustive code reference. Once you have code, study it to see how it works, then change things and see what effect it has.

commented: words. +7

koekoeksklok, (translation: cuckoo clock :?: ) I live near Antwerp, have many friends there. If you want to become my friend, don't do this again and read the forum policies as Ryshad already pointed out.

commented: Great! My Friend. +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.