• Log in or sign up for an account here: https://www.sythe.org/login

Problem For School - Finding Average

DeepSnow

Active Member
Joined
Jun 30, 2009
Sythe Gold
0
Messages
232
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.
 
Member of the Month Winner
Sythe's 10th Anniversary
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.

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.
 
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.
 
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.
 
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
 
#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.
 
Runescape Gamblingrunescape gambling
Back
Top