2 Replies - 141 Views - Last Post: 05 February 2012 - 12:05 PM Rate Topic: -----

Topic Sponsor:

#1 mrbrightside  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-January 12

Program that gives total of square root

Posted 05 February 2012 - 10:15 AM

I'm a beginner to C#. Does anyone know how to write a simple program using the numbers from 1 - 12 and output the number, the square of the number, the cube of the number and finally the square root of the number and at the end give me a grand total of the square roots?
Is This A Good Question/Topic? 0
  • +

Replies To: Program that gives total of square root

#2 tlhIn`toq  Icon User is offline

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3290
  • View blog
  • Posts: 6,898
  • Joined: 02-June 10

Re: Program that gives total of square root

Posted 05 February 2012 - 10:40 AM

View Postmrbrightside, on 05 February 2012 - 11:15 AM, said:

Does anyone know how to


Yes. I'm sure most of us do. (Sounds like about 25 lines of code as a wild guess before every trying it)

But as this sounds very much like your homework, and you haven't shown us any effort on your part to actually write your own code, nobody is going to just write it for you.

This is the 'Help me with my homework' article you wanted.
Stages of asking for homework help on a forum.
I don't want you to write my code, just give me ideas on how to solve my problem.
"It doesn't work" isn't good enough - Read this article

What have to you tried to code so far?
What part of what you have tried isn't working?
Are you getting error messages, or is it just not giving you the results you wanted?

(In other words, you at least have to make and show us your good faith effort to do your own coding. We are here to help you, not do it for you.)
What does this error mean?

Suggestion:
Don't replace lines of code that don't work. Instead comment them out and put your new attemps below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

// Try #1 - May 1, 0900hrs
//    code
//    code  
//    code
// Try #2 - May 2, 1700hrs   Okay, plan B.  What if I do it *this* way
//    code
//    code  
//    code
// Try #14 - May 3, 0500hrs after 5 cans of RedBull.  Maybe I should get some sleep. I can't think of anything else but this last idea
    code
    code  
    code


If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode Comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.

Newbie/Rookie said:

I have a little programming experience but I need to write ...


You need to start there. I can't say "I have little experience in speaking Russian, but I have been assigned to write a mystery novel in Russian. Can you help me?"

We can help you by saying "First learn basic programming and the language of C#. Then take on assignments." Could someone here write this program for you? Sure. Could someone here map out all the processes you need to follow and do the Software Design part of this in the slim hope you could code it from there? Sure. But we don't volunteer to do the job that you're either getting paid for, or getting a grade for. You may want to read this.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3 act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).


Resources, references and suggestions for new programmers. - Updated Jan 2012
Spoiler

This post has been edited by tlhIn`toq: 05 February 2012 - 10:42 AM

Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • Is that a raincoat?
  • member icon

Reputation: 1012
  • View blog
  • Posts: 3,816
  • Joined: 27-January 10

Re: Program that gives total of square root

Posted 05 February 2012 - 12:05 PM

Pseudo code time!

Does anyone know how to write a simple program using the numbers from 1 - 12
You can use Console.ReadLine() to get input from the console and save it to a variable.

Output the number
You can use Console.WriteLine() to output something.

Square of a number
In mathematical terms this is foo * foo. Say, "foo" looks like a variable right?

Cube of a number
Hm... foo * foo * foo? Yep

Square root of a number?
You can use Math.Sqrt(foo)

Hope this takes you down the right path. If you need more help, MAKE SURE TO POST WHAT YOU HAVE TRIED.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1