ok.
here are a list of things i cant fix. ive been trying for way to long now.
1. if more then 1000 values are told, will still continue with program.
2. if -max, min, average etc run, and 2 values are given they will work, but will cause a random segmentation fault. (BUT only with giving two values.)
3. -average doesnt give average.
4. -gta is ment to give all the values greater then the average. but doesnt do anything
5. -gt is ment to give all the values greater then valueX. which doesnt do anything either. -
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
int main(int argc, char ** argv)
-
{
-
// Mainline Variable Declarations
-
FILE * output = stdout;
-
FILE * input = stdin;
-
-
int count;
-
int maxsize;
-
-
float valueX;
-
float total;
-
float average;
-
float max;
-
float min;
-
float maxX;
-
float maxA;
-
-
fprintf(output,"please enter the number of values that will be given: "); fflush(output);
-
fscanf(input,"%d",&maxsize);
-
-
float values[maxsize];
-
-
-
if (maxsize<=1000 || maxsize>0)
-
{
-
for (count=0;count<maxsize;count++)
-
{
-
fprintf(output,"please enter a value: "); fflush(output);
-
fscanf(input,"%f",&values[count]);
-
}
-
}
-
else
-
{
-
fprintf(output,"please enter a value greater then 0 or 1000 or less\n");
-
}
-
-
for (count=0; count<=argc-1;count++)
-
{
-
if (strcmp(argv[count],"-help")==0)
-
{
-
fprintf(output,"help\n");
-
return 0;
-
}
-
-
if (strcmp(argv[count],"-max")==0)
-
{
-
max=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
if ( values[count]>max)
-
{
-
max=values[count];
-
}
-
}
-
fprintf(output,"the max value is: %f\n",max);
-
}
-
-
if (strcmp(argv[count],"-min")==0)
-
{
-
min=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
if (values[count]<min)
-
{
-
min=values[count];
-
}
-
}
-
fprintf(output,"the min value is: %f\n",min);
-
}
-
if (strcmp(argv[count],"-average")==0)
-
{
-
total=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
total+=values[count];
-
}
-
average=total/2;
-
-
fprintf(output,"the average for these values is: %f\n",average);
-
}
-
if (strcmp(argv[count],"-gta")==0)
-
{
-
for (count=0;count<maxsize;count++)
-
{
-
total=total+values[count];
-
}
-
average=total/2;
-
-
maxA=average
-
for (count=average; count<maxsize;count++)
-
{
-
if (values[count]>maxA)
-
{
-
maxA=values[count];
-
}
-
fprintf(output,"values greater then the average are: %f\n", maxA);
-
}
-
}
-
-
if (strcmp(argv[count],"-gt")==0)
-
{
-
if (argc<4)
-
{
-
fprintf(output,"please enter a value\n");
-
}
-
else
-
{
-
valueX = atof(argv[count+1]);//takes value off the command line and assigns to valuex
-
-
maxX=valueX;
-
for (count=valueX; count<maxsize;count++)
-
{
-
if (values[count]>maxX)
-
{
-
maxX=values[count];
-
fprintf(output,"values which are greater: %f\n",maxX);
-
}
-
}
-
}
-
}
-
}
-
}
-
8 1676
ok.
here are a list of things i cant fix. ive been trying for way to long now.
1. if more then 1000 values are told, will still continue with program.
2. if -max, min, average etc run, and 2 values are given they will work, but will cause a random segmentation fault. (BUT only with giving two values.)
3. -average doesnt give average.
4. -gta is ment to give all the values greater then the average. but doesnt do anything
5. -gt is ment to give all the values greater then valueX. which doesnt do anything either. -
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
int main(int argc, char ** argv)
-
{
-
// Mainline Variable Declarations
-
FILE * output = stdout;
-
FILE * input = stdin;
-
-
int count;
-
int maxsize;
-
-
float valueX;
-
float total;
-
float average;
-
float max;
-
float min;
-
float maxX;
-
float maxA;
-
-
fprintf(output,"please enter the number of values that will be given: "); fflush(output);
-
fscanf(input,"%d",&maxsize);
-
-
float values[maxsize];
-
-
-
if (maxsize<=1000 || maxsize>0)
-
{
-
for (count=0;count<maxsize;count++)
-
{
-
fprintf(output,"please enter a value: "); fflush(output);
-
fscanf(input,"%f",&values[count]);
-
}
-
}
-
else
-
{
-
fprintf(output,"please enter a value greater then 0 or 1000 or less\n");
-
}
-
-
for (count=0; count<=argc-1;count++)
-
{
-
if (strcmp(argv[count],"-help")==0)
-
{
-
fprintf(output,"help\n");
-
return 0;
-
}
-
-
if (strcmp(argv[count],"-max")==0)
-
{
-
max=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
if ( values[count]>max)
-
{
-
max=values[count];
-
}
-
}
-
fprintf(output,"the max value is: %f\n",max);
-
}
-
-
if (strcmp(argv[count],"-min")==0)
-
{
-
min=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
if (values[count]<min)
-
{
-
min=values[count];
-
}
-
}
-
fprintf(output,"the min value is: %f\n",min);
-
}
-
if (strcmp(argv[count],"-average")==0)
-
{
-
total=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
total+=values[count];
-
}
-
average=total/2;
-
-
fprintf(output,"the average for these values is: %f\n",average);
-
}
-
if (strcmp(argv[count],"-gta")==0)
-
{
-
for (count=0;count<maxsize;count++)
-
{
-
total=total+values[count];
-
}
-
average=total/2;
-
-
maxA=average
-
for (count=average; count<maxsize;count++)
-
{
-
if (values[count]>maxA)
-
{
-
maxA=values[count];
-
}
-
fprintf(output,"values greater then the average are: %f\n", maxA);
-
}
-
}
-
-
if (strcmp(argv[count],"-gt")==0)
-
{
-
if (argc<4)
-
{
-
fprintf(output,"please enter a value\n");
-
}
-
else
-
{
-
valueX = atof(argv[count+1]);//takes value off the command line and assigns to valuex
-
-
maxX=valueX;
-
for (count=valueX; count<maxsize;count++)
-
{
-
if (values[count]>maxX)
-
{
-
maxX=values[count];
-
fprintf(output,"values which are greater: %f\n",maxX);
-
}
-
}
-
}
-
}
-
}
-
}
-
hi, i guess ur requirement will work with this code... - #include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
int main(int argc, char ** argv)
-
{
-
// Mainline Variable Declarations
-
FILE * output = stdout;
-
FILE * input = stdin;
-
-
int count;
-
int maxsize;
-
-
float valueX;
-
float total;
-
float average;
-
float max;
-
float min;
-
float maxX;
-
float maxA;
-
-
fprintf(output,"please enter the number of values that will be given: "); fflush(output);
-
fscanf(input,"%d",&maxsize);
-
-
float values[maxsize];
-
-
-
if (maxsize>0 && maxsize<=1000)
-
{
-
for (count=0;count<maxsize;count++)
-
{
-
fprintf(output,"please enter a value: "); fflush(output);
-
fscanf(input,"%f",&values[count]);
-
}
-
}
-
else
-
{
-
fprintf(output,"please enter a value greater then 0 or 1000 or less\n");
-
}
-
-
for (count=0; count<=argc-1;count++)
-
{
-
if (strcmp(argv[count],"-help")==0)
-
{
-
fprintf(output,"help\n");
-
return 0;
-
}
-
-
if (strcmp(argv[count],"-max")==0)
-
{
-
max=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
if ( values[count]>max)
-
{
-
max=values[count];
-
}
-
}
-
fprintf(output,"the max value is: %f\n",max);
-
}
-
-
if (strcmp(argv[count],"-min")==0)
-
{
-
min=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
if (values[count]<min)
-
{
-
min=values[count];
-
}
-
}
-
fprintf(output,"the min value is: %f\n",min);
-
}
-
if (strcmp(argv[count],"-average")==0)
-
{
-
total=values[0];
-
for (count=0;count<maxsize;count++)
-
{
-
total+=values[count];
-
}
-
average=total/maxsize;
-
-
fprintf(output,"the average for these values is: %f\n",average);
-
}
-
if (strcmp(argv[count],"-gta")==0)
-
{
-
maxA=average;
-
for (count=0; count<maxsize;count++)
-
{
-
if (values[count]>maxA)
-
{
-
fprintf(output,"values greater then the average are: %f\n", values[count]);
-
-
}
-
}
-
}
-
-
if (strcmp(argv[count],"-gt")==0)
-
{
-
if (argc<4)
-
{
-
fprintf(output,"please enter a value\n");
-
}
-
else
-
{
-
valueX = atof(argv[count+1]);//takes value off the command line and assigns to valuex
-
-
maxX=valueX;
-
for (count=0; count<maxsize;count++)
-
{
-
if (values[count]>maxX)
-
{
-
fprintf(output,"values which are greater: %f\n",values[count]);
-
}
-
}
-
}
-
}
-
}
-
}
As i dont know ur requirements properly.. i cud solve some of your problems..
let me know if u get some other problems...
it fixed a bit.
lets see..
average seems to be printing out random numbers.
not the average.
-gta.
this command is ment to find the average.
then print out all the values greater then the average.
-gt.
this command is ment to get the user to input a value.
then print all values greater then that.
everything else works fine.
If that is the case...
above code should work..
-gta prints out the 5 values given, not the values greater then the average..
i will try..
does the code to find the average have to be typed again under -gta
well i got it.
just testing -gt now.
that wasnt expected.
with -gt.
the else statement didnt work.
i had to change it to an else if statement.
so i put else if (argc=3).
dont know if its the best way to put it. but it works. :D
oh theres 1 thing i want to edit.
is it possible.
if -help is specified.
i want it to give a list of help commands then stop.
because at the moment it still asks for the array values.
At this point, your program is asking for the values before it checks for the "-help" flag. If you want the program to stop before entering values if -help is typed in the command line, you will have to check for "-help" before your fscanf loop.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: drdoubt |
last post by:
using namespace std
In my C++ program, even after applying , I need to use the std
namespace with the scope resolution operator, like, std::cout,
std::vector. This I found a little bit...
|
by: James Fortune |
last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't
understand why people who know how to write code to completely replace
a front end do not write something that will automate...
|
by: my-wings |
last post by:
I think I've painted myself into a corner, and I'm hoping someone can help
me out.
I have a table of books (tblBooks), which includes a field (strPubName) for
Publisher Name and another field...
|
by: Timothy Shih |
last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I
wrote a simple function which takes in 2 buffers (one a byte buffer, one a
char buffer) and copies the contents of the byte...
|
by: Chad Z. Hower aka Kudzu |
last post by:
A few of you may recognize me from the recent posts I have made about Indy
<http://www.indyproject.org/indy.html>
Those of you coming to .net from the Delphi world know truly how unique and...
|
by: Phil |
last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and
made into a TIF file and placed on the client (could be in temp internet
dir). The reason we need it in TIF format is...
|
by: Keith Kowalski |
last post by:
I anm opening up a text file reading the lines of the file that refer to a
tif image in that file, If the tif image does not exist I need it to send an
email stating that the file doesn't exist...
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to...
|
by: Quas.co.ua |
last post by:
Hello all.
I need your help.
I need C compler to make demo of some technologie.
This C compiler I need to write program
which after run will be located in one segment of memory
and it...
|
by: mike |
last post by:
I help manage a large web site, one that has over
600 html pages... It's a reference site for ham radio
folks and as an example, one page indexes over
1.8 gb of on-line PDF documents.
The site...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |