immediate help with c# required

Off-topic posts of interest to the World of Warcraft community.
User avatar
Wilcox
Posts: 1589
Joined: 16 Dec 2012 13:37
Location: Kebabland

immediate help with c# required

#1 » Post by Wilcox » 21 Mar 2016 18:51

im 1st grade yet in university, studying IT & computer engineering, they are teaching us C# and it's my first time doing this shit since I decided to be lazy and skip all the classes over the course of 6 weeks

this is my exam question(according to 2nd grades), please take it very serious

i need to create the increment symbol using the "for loop", the program that finds the total value when you add up numbers from a to b

for example, the total of numbers from 1 to 10 is 55, i know that because im an expert at maths but I got no clue how to make this happen with C#

wtb immediate help, i have about 14 hours left until the exam

User avatar
belendor
Posts: 951
Joined: 18 Nov 2010 21:02

Re: immediate help with c# required

#2 » Post by belendor » 21 Mar 2016 19:16

Code: Select all

using System;
namespace Loops
{
class Program
{
int number=0;
static void Main(string[] args)
{
for (int i = 1; i <= 5; i++)
{
number= number + i;
}
}
}
}



change the 5 to the number u want to count up to, you can also make this a var and fill in a number u like, it's been a while since i did c# lol
Belendor lvl 80 prot/holy paladin - The original

No need to mention the other paladins.

Best word in west flemish 'toetoet'

User avatar
Wilcox
Posts: 1589
Joined: 16 Dec 2012 13:37
Location: Kebabland

Re: immediate help with c# required

#3 » Post by Wilcox » 21 Mar 2016 19:19

i don't have any studios installed currently, did you test this and does it work? for example when you write 1 and 50 does it say 1275

im gonna look at this shit from my phone during the exam xd

User avatar
belendor
Posts: 951
Joined: 18 Nov 2010 21:02

Re: immediate help with c# required

#4 » Post by belendor » 21 Mar 2016 19:29

using System.IO;
using System;

class Program
{
static void Main()
{
int number=0;
Console.WriteLine("Hello, World!");
for (int i = 1; i <= 5; i++)
{
number= number + i;
Console.WriteLine(number);
}
}
}

copy paste it in
http://www.tutorialspoint.com/compile_csharp_online.php
Belendor lvl 80 prot/holy paladin - The original

No need to mention the other paladins.

Best word in west flemish 'toetoet'

User avatar
Gnurg
Posts: 2420
Joined: 28 Jan 2013 19:38
Location: Oslo, Norway

Re: immediate help with c# required

#5 » Post by Gnurg » 21 Mar 2016 19:44

I highly doubt you would get the same question the year after, so in those 14 hours, I would rather get to know the basic of each topic you have had over the course thus far to be prepared for most of it. And just one question about a loop seems awfully easy for an exam?
HAI
CAN HAZ STDIO?
VISIBLE "HAI WORLD, IZ GNURF!"
KTHXBYE

User avatar
Matsy
Posts: 1246
Joined: 28 Aug 2010 19:17
Location: United Kingdom

Re: immediate help with c# required

#6 » Post by Matsy » 21 Mar 2016 19:50

Still dont understand what your asking for lol, a loop to add up a string of numbers? an array of numbers? numbers you type in and get an answer back?
Maybe I'm just stupid....
Matsy pls
Mats - Frost PVE Troll Death Knight - Retired
Matsy - Moonkin/Restoration Druid (Laz0r Chicken)
Mat - Beastmaster Orc Hunter
Matz -Retribution Paladin
Matu - Troll Shadow Priest
Bolts - Elemental Troll Shaman
Kungfu - Orc Fury Warrior
Trollage - Troll Arcane Mage
Mato - Orc Affliction Warlock
Findme - Troll Assassination Rogue

I Pity the Fool who's illogical
Friends are just people you hate the least
I reject your reality and substitute my own

User avatar
jamhead
Posts: 348
Joined: 21 Nov 2010 17:40

Re: immediate help with c# required

#7 » Post by jamhead » 21 Mar 2016 19:58

Here's a nice commented version if you need to understand what's happening in Belendor's answer:

Code: Select all


using System.IO;
using System;

class Program
{
static void Main()
{

// start out by declaring variables a and b
// "finds the total value when you add up numbers from a to b"
int a = 1;
int b = 50;

// Make another variable to keep track of the total each time
int total=0;

// Make a for loop that starts at "a" and goes up to be "b", incrementing by one each time
// "create the increment symbol using the "for loop""
for (int i = a; i <= b; i++)
{

// add the value of each i to our running total
total = total + i;

// write to the console the total after each loop
Console.WriteLine(number);
}




}
}
Slight improvement: explicitly making a and b variables since the question states that.
Currently addicted to hearthstone playing at legend rank. Feel free to add jamhead#2986

My quest to prove anybody can paint - jamheadii.deviantart.com

Check out my new puzzle game Slide!

User avatar
Polkic
Former Staff
Posts: 1059
Joined: 21 Dec 2012 00:02
Location: Slovenia

Re: immediate help with c# required

#8 » Post by Polkic » 21 Mar 2016 20:00

He needs program that adds numbers from 1 to 10 ( 1+2+3+4+5+6+7+8+9+10).
Image

User avatar
Longi
Posts: 768
Joined: 07 Jan 2014 11:14
Location: Cenarion Hold

Re: immediate help with c# required

#9 » Post by Longi » 21 Mar 2016 20:01

he wants to make " program " to counting a set of numbers ... the set of numbers starts with " A " and ends with " B "

so lets say ... program will say

- Write first number
- you will write 5
- program wil ask for second number
- you will write 15
- press enter or random key ..for example

and program will do 5+6+7+8+9+10+11+12+13+14+15

- your number is 110

end :D


Image



User avatar
Gnurg
Posts: 2420
Joined: 28 Jan 2013 19:38
Location: Oslo, Norway

Re: immediate help with c# required

#10 » Post by Gnurg » 21 Mar 2016 20:02

Matsy wrote:Still dont understand what your asking for lol, a loop to add up a string of numbers? an array of numbers?
Maybe I'm just stupid....
I think he wants a loop that adds the numbers from number a to number b. So in his example a was 1 and b 10.

Code: Select all

static int addNumbersFromAToB(int a, int b) {
int sum = 0;

while (a <= b) { // (a < b) if you do not want to include number b.
sum += a++;
}

return sum;
}
HAI
CAN HAZ STDIO?
VISIBLE "HAI WORLD, IZ GNURF!"
KTHXBYE

User avatar
Matsy
Posts: 1246
Joined: 28 Aug 2010 19:17
Location: United Kingdom

Re: immediate help with c# required

#11 » Post by Matsy » 21 Mar 2016 20:05

Yes but how does he get the values? does he enter them? are they already in a string or array? whut
If its just an array he can use this as a adding mechanism

Code: Select all

int sum = arr.Sum();
Console.WriteLine(sum);
Unless it has to be a loop for some god awful reason (if its an array)..
If it has to be just use

Code: Select all

for (int i = 0; i < arr.Length; i++)
{
sum += arr[i];
}
Or the one you provided will work aswell, but its purely decided on how the numbers from a to b are assigned.
Last edited by Matsy on 21 Mar 2016 20:09, edited 3 times in total.
Matsy pls
Mats - Frost PVE Troll Death Knight - Retired
Matsy - Moonkin/Restoration Druid (Laz0r Chicken)
Mat - Beastmaster Orc Hunter
Matz -Retribution Paladin
Matu - Troll Shadow Priest
Bolts - Elemental Troll Shaman
Kungfu - Orc Fury Warrior
Trollage - Troll Arcane Mage
Mato - Orc Affliction Warlock
Findme - Troll Assassination Rogue

I Pity the Fool who's illogical
Friends are just people you hate the least
I reject your reality and substitute my own

User avatar
Longi
Posts: 768
Joined: 07 Jan 2014 11:14
Location: Cenarion Hold

Re: immediate help with c# required

#12 » Post by Longi » 21 Mar 2016 20:08

j=0; for(i='a',i<='b',i++){j=j+i}
printf(j)

mby somthing like this :D i rly dont know it was loooong time ago i had this in school :D


Image



User avatar
Gnurg
Posts: 2420
Joined: 28 Jan 2013 19:38
Location: Oslo, Norway

Re: immediate help with c# required

#13 » Post by Gnurg » 21 Mar 2016 20:12

Matsy wrote:Yes but how does he get the values? does he enter them? are they already in a string or array? whut
It's likely a paper exam and he is to create a function similiar to the one I wrote. I doubt an examiner is interrested in c# i/o syntax.
HAI
CAN HAZ STDIO?
VISIBLE "HAI WORLD, IZ GNURF!"
KTHXBYE

User avatar
belendor
Posts: 951
Joined: 18 Nov 2010 21:02

Re: immediate help with c# required

#14 » Post by belendor » 21 Mar 2016 20:22

bitches pls, come program COBOL with me.
Belendor lvl 80 prot/holy paladin - The original

No need to mention the other paladins.

Best word in west flemish 'toetoet'

User avatar
Gnurg
Posts: 2420
Joined: 28 Jan 2013 19:38
Location: Oslo, Norway

Re: immediate help with c# required

#15 » Post by Gnurg » 21 Mar 2016 20:26

belendor wrote:bitches pls, come program COBOL with me.
Scheme is more fun with all those god damn parentheses. >..............<
HAI
CAN HAZ STDIO?
VISIBLE "HAI WORLD, IZ GNURF!"
KTHXBYE

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests