Alrighty then. I haven't done much programming, and I have this little sucker to do for a class. I don't know exactly what I'm doing, as you will see.
----------------
#include <stdio.h>
#define sqroot(x) (x / x);
float variance_function(float, float);
int main(int argc, char *argv[])
{
/* Declare and initialise some variables */
float sum = 0.0, mean = 0.0, standev = 0.0, variance = 0.0;
int num_of_entries = 0;
char do_or_not = 'n';
/* Initial user prompt */
printf("\nWelcome to number-thingamajig!");
printf("\nTo use the programme, enter Y, else enter N: ");
scanf("%c", &do_or_not);
/* Run programme in a whopping great big if/else */
if(do_or_not == 'N' || 'n')
{
printf("\nExiting programme...\n\n");
break;
}
else
{
/* Gather input */
while(scanf() != "\n")
{
sum += scanf("%f");
num_of_entries++;
}
/* Work out the mean, standard deviation, and variance here */
mean = ( sum / num_of_entries );
variance = variance_function(sum, num_of_entries);
standev = sqroot(variance);
/* Display output */
printf("\nRESULTS");
printf("\nNumber of entries: %d", num_of_entries);
printf("\nSum of entries: %f", sum);
printf("\nMean: %f", mean);
printf("\nStandard Deviation: %f", standev);
printf("\nVariance: %f", variance);
printf("\n\nThank you, come again!");
}
}
float variance_function(float sum, float num_of_entries)
{
return ((sum * sum)/num_of_entries) - (num_of_entries * num_of_entries);
}
----------------
See, it's supposed to take in a bunch of floats and work out the sum, mean, standard deviation, and variance, then printf() them all out. The thing is, it also needs the argc and argv. What are the argc and argv in there for if I'm to have the programme accepting entries within a loop? And how do I make it all work?
Thanks.
----------------
#include <stdio.h>
#define sqroot(x) (x / x);
float variance_function(float, float);
int main(int argc, char *argv[])
{
/* Declare and initialise some variables */
float sum = 0.0, mean = 0.0, standev = 0.0, variance = 0.0;
int num_of_entries = 0;
char do_or_not = 'n';
/* Initial user prompt */
printf("\nWelcome to number-thingamajig!");
printf("\nTo use the programme, enter Y, else enter N: ");
scanf("%c", &do_or_not);
/* Run programme in a whopping great big if/else */
if(do_or_not == 'N' || 'n')
{
printf("\nExiting programme...\n\n");
break;
}
else
{
/* Gather input */
while(scanf() != "\n")
{
sum += scanf("%f");
num_of_entries++;
}
/* Work out the mean, standard deviation, and variance here */
mean = ( sum / num_of_entries );
variance = variance_function(sum, num_of_entries);
standev = sqroot(variance);
/* Display output */
printf("\nRESULTS");
printf("\nNumber of entries: %d", num_of_entries);
printf("\nSum of entries: %f", sum);
printf("\nMean: %f", mean);
printf("\nStandard Deviation: %f", standev);
printf("\nVariance: %f", variance);
printf("\n\nThank you, come again!");
}
}
float variance_function(float sum, float num_of_entries)
{
return ((sum * sum)/num_of_entries) - (num_of_entries * num_of_entries);
}
----------------
See, it's supposed to take in a bunch of floats and work out the sum, mean, standard deviation, and variance, then printf() them all out. The thing is, it also needs the argc and argv. What are the argc and argv in there for if I'm to have the programme accepting entries within a loop? And how do I make it all work?
Thanks.