| Problem For School - Finding Average |
 |

10-06-2009, 09:37 PM
|
 |
Active Member
|
|
Join Date: Jul 2009
Posts: 227
|
|
Problem For School - Finding Average
Hey, this should be simple for most of you;
Code:
#include <stdio.h>
int main()
{
int i;
for(i = 0; i<10; i++)
{
printf("%d\n", i);
}
return(0);
}
Now using a "for" loop or something similar to that one, write a program that prompts the user for how many numbers they wish to average, count up the numbers they typed in, and average them. I believe it will need to be functionless, but you have to declare some crap, I don't know. Printf and Scanf.
We are using something called C Sharp? But apparently it's pretty much C. We program in VI while connected to a Linux machine. I've been doing good up till shortly, when we had to make a simple calculator. I couldn't submit anything and am now 400/500 points, or a 80 percent. Even getting 100 on this next assignment will bring me to an 83, this is the one class I am not doing well in, and I will not fucking fail an elective.
Payment may be possible, as I said, I do not understand this shit and will most likely be coming back here for more assistance. [email protected] or nightmare3695 AIM, or just post back here. To be honest, I don't need help, yet just the entire completed code I can copy into notepad. If you have some weird issue with getting paid for writing a code, spill out how to start this. And I mean be basic, I understand basic, and that's it.
Thanks
*and jesus, be basic with writing the code too. It can't look too much like something I ripped off the internet. Because that stuff is available, but uses weird ass shit we don't know yet.
__________________
Last edited by DeepSnow : 10-06-2009 at 09:39 PM.
|

10-15-2009, 06:12 PM
|
|
Iloveroy
BANNED
|
|
Join Date: Nov 2008
Location: BC, Canada
Posts: 2,343
|
|
Re: Problem For School - Finding Average
Still need this?
I will write it for you when I get home, in school ATM.
|

10-15-2009, 10:35 PM
|
 |
When They Cry...
|
|
Join Date: Jan 2007
Location: Japan
Posts: 4,404
|
|
Re: Problem For School - Finding Average
Quote:
Originally Posted by DeepSnow
Hey, this should be simple for most of you;
Code:
#include <stdio.h>
int main()
{
int i;
for(i = 0; i<10; i++)
{
printf("%d\n", i);
}
return(0);
}
Now using a "for" loop or something similar to that one, write a program that prompts the user for how many numbers they wish to average, count up the numbers they typed in, and average them. I believe it will need to be functionless, but you have to declare some crap, I don't know. Printf and Scanf.
We are using something called C Sharp? But apparently it's pretty much C. We program in VI while connected to a Linux machine. I've been doing good up till shortly, when we had to make a simple calculator. I couldn't submit anything and am now 400/500 points, or a 80 percent. Even getting 100 on this next assignment will bring me to an 83, this is the one class I am not doing well in, and I will not fucking fail an elective.
Payment may be possible, as I said, I do not understand this shit and will most likely be coming back here for more assistance. [email protected] or nightmare3695 AIM, or just post back here. To be honest, I don't need help, yet just the entire completed code I can copy into notepad. If you have some weird issue with getting paid for writing a code, spill out how to start this. And I mean be basic, I understand basic, and that's it.
Thanks
*and jesus, be basic with writing the code too. It can't look too much like something I ripped off the internet. Because that stuff is available, but uses weird ass shit we don't know yet.
|
C# is vastly different to C. C# is more akin to Java than anything, and runs upon the .Net framework.
Have you ever actually tried to learn this stuff before? It's extremely basic stuff. Perhaps you haven't been paying attention in class. If so, you probably deserve to fail. You sound like you're making a demand rather than asking for help. The internet is not your army, so you could at least be polite.
Quote:
|
but you have to declare some crap, I don't know. Printf and Scanf.
|
You're going to need to say more than that or you'll seriously confuse people. Do you mean you need to include the stdio header to use printf() and scanf()?
I'm going to school soon, hence I won't have time to show you how to do this right now.
__________________
Quote:
[14:54:13] <&Filefragg> x9 is made of 5 glow in the dark gorilla dildos vibrating in unison.
[14:54:19] <%TDD> hot
[14:54:22] <+Aoi> Win
[14:54:23] <x9> I TOLD YOU NOT TO TELL ANYONE, DAMNIT
|
|

10-17-2009, 02:22 AM
|
 |
Apprentice
|
|
Join Date: Nov 2007
Posts: 930
|
|
Re: Problem For School - Finding Average
If you are using a C#, you can do it in the console.
And write it Console.Write("Enter how many average you want to compute: ");
Then follows the loop.
I can do this, but you aren't nice to begin with asking for help.
Maybe a little nicer would make people help you.
|

10-17-2009, 04:10 AM
|
|
Newcomer
|
|
Join Date: Oct 2009
Posts: 7
|
|
Re: Problem For School - Finding Average
Code:
using System;
namespace Application1
{
class Program
{
static void Main(string[] args)
{
double i = 0;
double sum = 0;
for (i = 0; i < 10; i++)
{
sum = sum + i;
}
Console.WriteLine(sum / i);
}
}
}
Can't get much more basic looking than that. Suggest reading through some beginners guides to understand the C# code before you turn it in.
Last edited by WCCobra : 10-17-2009 at 04:11 AM.
Reason: typo
|

10-17-2009, 11:42 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 91
|
|
Re: Problem For School - Finding Average
80% is BAD? Are you retarded? You deserve to fail... but I am feeling generous.
Code:
#include <stdio.h>
main() {
int num_count;
printf("input # of numbers to average: ");
scanf("%d", &num_count);
int i;
int sum = 0;
for (i = 0; i < num_count; ++i) {
int input;
scanf("%d", &input);
sum += input;
}
printf("average: %d\n", sum / num_count);
return 0;
}
note the average is calculated using integer arithmetic, and not floating point; it is not all too accurate. it prompts for the number of numbers to average, and then you input the numbers and hit enter after each:
Code:
input # of numbers to average: 2
1
3
average: 2
|

12-01-2009, 11:35 AM
|
|
Active Member
|
|
Join Date: Nov 2005
Posts: 158
|
|
Re: Problem For School - Finding Average
So do you want it coded in C# or C?
|

01-11-2010, 04:31 PM
|
 |
Active Member
|
|
Join Date: Aug 2009
Location: Sythe!
Posts: 172
|
|
Re: Problem For School - Finding Average
Quote:
#include <stdio.h>
main() {
int num_count;
printf("input # of numbers to average: ");
scanf("%d", &num_count);
int i;
int sum = 0;
for (i = 0; i < num_count; ++i) {
int input;
scanf("%d", &input);
sum += input;
}
printf("average: %d\n", sum / num_count);
return 0;
}
|
You dont need to declare int input inside loop, just put outside loop. Scanf function will override the lastest value every loop count.
Last edited by KB2486 : 01-11-2010 at 04:35 PM.
|
 |
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|