immediate help with c# required
immediate help with c# required
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
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
Re: immediate help with c# required
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'
No need to mention the other paladins.
Best word in west flemish 'toetoet'
Re: immediate help with c# required
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
im gonna look at this shit from my phone during the exam xd
Re: immediate help with c# required
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
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'
No need to mention the other paladins.
Best word in west flemish 'toetoet'
Re: immediate help with c# required
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?
Re: immediate help with c# required
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....
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
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
Re: immediate help with c# required
Here's a nice commented version if you need to understand what's happening in Belendor's answer:
Slight improvement: explicitly making a and b variables since the question states that.
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);
}
}
}
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!
My quest to prove anybody can paint - jamheadii.deviantart.com
Check out my new puzzle game Slide!
Re: immediate help with c# required
He needs program that adds numbers from 1 to 10 ( 1+2+3+4+5+6+7+8+9+10).
Re: immediate help with c# required
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
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
Re: immediate help with c# required
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.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....
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;
}
Re: immediate help with c# required
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
Unless it has to be a loop for some god awful reason (if its an array)..
If it has to be just use
Or the one you provided will work aswell, but its purely decided on how the numbers from a to b are assigned.
If its just an array he can use this as a adding mechanism
Code: Select all
int sum = arr.Sum();
Console.WriteLine(sum);
If it has to be just use
Code: Select all
for (int i = 0; i < arr.Length; i++)
{
sum += arr[i];
}
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
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
Re: immediate help with c# required
j=0; for(i='a',i<='b',i++){j=j+i}
printf(j)
mby somthing like this i rly dont know it was loooong time ago i had this in school
printf(j)
mby somthing like this i rly dont know it was loooong time ago i had this in school
Re: immediate help with c# required
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.Matsy wrote:Yes but how does he get the values? does he enter them? are they already in a string or array? whut
Re: immediate help with c# required
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'
No need to mention the other paladins.
Best word in west flemish 'toetoet'
Re: immediate help with c# required
Scheme is more fun with all those god damn parentheses. >..............<belendor wrote:bitches pls, come program COBOL with me.
Who is online
Users browsing this forum: No registered users and 14 guests