Please Please Help!!!!!! 
Author Message
 Please Please Help!!!!!!

I am trying to complete this little program  for an assignment but the thing
will not execute as it should, would someone out there please help and give
me some pointers?

/*
 *  Program to read in a set of floating-point TMS temperatures
 *  and to sort them into separate positive and negative arrays
 */

#include <conio.h>
#include <stdio.h>

float in_float(void);
void wait(void);

/*
 * main() function
 * ===============
 */
main()
 {
 int i=0, j=0, k=0, l=0;
 float temp, temps[20], postemps[20], negtemps[20];
 clrscr();
 cprintf("Please type in the temperatures\r\n");
 temp = in_float();
 cprintf("\r\n");
 while ((temp<=999.9) && (i<20));
  {
  int(i) = temp;
  i++;
  temp = in_float();
  cprintf("\r\n");
  }
 for (j=0; j<i; j++)
  {
  if (i>=0)
       {
       i= postemps;
       }
       else
    {
   i= negtemps;
    }
        }

 cprintf("The %i positive temperatures were:-\r\n",l);
 for (j=0; j<l; j++)
  {
  cprintf(" %f\r\n",postemps[j]);
  }
 cprintf("The %i negative temperatures were:-\r\n",k);
 for (j=0; j>l; j--)
  {
  cprintf(" %f\r\n",negtemps[l]);
  }

 wait();
 }
/*
 * end of main()
 */

/*
 * function in_float()
 * ===================
 * inputs a floating-point number from the keyboard
 */

float in_float(void)
 {
 char tbuff[12];
 float d;
 int i;
 tbuff[0] = 10;
 cgets(tbuff);
 sscanf(&tbuff[2],"%f",&d);
 return(d);
 }
/*
 * end of in_float()
 */

/*
 * function wait()
 * ===============
 * waits for a keypress
 */

void wait(void)
 {
 cprintf("\r\nPress any key to terminate");
 getch();
 }
/*
 * end of wait()
 */

Mark Pease

--



Thu, 19 Sep 2002 04:00:00 GMT  
 Please Please Help!!!!!!

Quote:
Catherine Pease writes:
>I am trying to complete this little program  for an assignment but the thing
>will not execute as it should, would someone out there please help and give
>me some pointers?

I don't think it executes at all, does it??? I can't imagine *any* compiler
that accepts this.

 What follows is a copy of your code that now compiles.  I didn't try to run
it.  You have cprint() all over the place and I don't know what  that is.
There is also a call on the mysterious cgets() that I don't have.  I commented
several lines out, using // for a C++ compiler.  Tried to draw attention to
what I did with ****

Try to incororate these changes  into your program and see what happens.

/*
 *  Program to read in a set of floating-point TMS temperatures
 *  and to sort them into separate positive and negative arrays
 */

#include <conio.h>
#include <stdio.h>

float in_float(void);
void wait(void);

/*
 * main() function
 * ===============
 */
void test()   //**** i changed this.  you can // change it back
 {
 int i=0, j=0, k=0, l=0;
 float temp, temps[20], postemps[20], negtemps[20];
 clrscr();
 //cprintf("Please type in the temperatures\r\n");
 temp = in_float();
 //cprintf("\r\n");
 while ((temp<=999.9) && (i<20));
  {
  int(i) = temp;
  i++;
  temp = in_float();
  //cprintf("\r\n");
  }
 for (j=0; j<i; j++)
  {
  if (i>=0)
       {
//       i= postemps;
  //     ****postemps is an array.  which element of the array do you want to
go to i?
       }
       else
    {
  // i= negtemps;   **** same as above
    }
        }

 //cprintf("The %i positive temperatures were:-\r\n",l);
 for (j=0; j<l; j++)
  {
  //cprintf(" %f\r\n",postemps[j]);
  }
 //cprintf("The %i negative temperatures were:-\r\n",k);
 for (j=0; j>l; j--)
  {
  //cprintf(" %f\r\n",negtemps[l]);
  }

 wait();
  }  
/*
 * end of main()
 */

/*
 * function in_float()
 * ===================
 * inputs a floating-point number from the keyboard
 */

float in_float(void)
 {
 char tbuff[12];
 float d;
 int i;
 tbuff[0] = 10;
 //cgets(tbuff);  // complains no prototype
 sscanf(&tbuff[2],"%f",&d);
 return(d);
 }
/*
 * end of in_float()
 */

/*
 * function wait(void)
 * ===============
 * waits for a keypress
 */

void wait(void)  //*** I don't know if I changed something here  or not
 {
 //cprintf("\r\nPress any key to terminate");
 getch();
 }
/*
 * end of wait()
 */



Thu, 19 Sep 2002 04:00:00 GMT  
 Please Please Help!!!!!!
Catherine Pease a crit dans le message ...
Quote:
>#include <conio.h>

Why are you again posting non standard C ? Maybe you like flammes ?

--
-hs- "Stove"
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
--



Sat, 21 Sep 2002 03:00:00 GMT  
 Please Please Help!!!!!!

Quote:
>  while ((temp<=999.9) && (i<20));

                                  ^
--
              /"\                              m i k e    b u r r e l l

               X        AGAINST HTML MAIL      http://mikpos.dyndns.org
              / \
--



Sat, 21 Sep 2002 03:00:00 GMT  
 Please Please Help!!!!!!
  This followup restricted to comp.lang.c only since my ISP seems to
be having trouble posting to c.l.c.moderated for some reason. Feel
free to post followups to either or both groups as you will.

Groovy hepcat Catherine Pease was jivin' on 02 Apr 2000 21:35:48 GMT
in comp.lang.c.moderated.
Please Please Help!!!!!!'s a cool scene! Dig it!

Quote:
>I am trying to complete this little program  for an assignment but the thing
>will not execute as it should, would someone out there please help and give
>me some pointers?

  I haven't spent the time to debug the program completely or look at
it too closely, but here are some obvious things you need to work on
even before trying to debug the program.

Quote:
>/*
> *  Program to read in a set of floating-point TMS temperatures
> *  and to sort them into separate positive and negative arrays
> */

>#include <conio.h>

  Oh gawd blimey! How many times must they be told not to use
non-standard things here? If you must use these extentions, please
post in a group that recognises these extentions.

Quote:
>#include <stdio.h>

>float in_float(void);
>void wait(void);

>/*
> * main() function
> * ===============
> */

  Yes, we can see it's the main() function. Please don't put such
silly, useless comments in your code. They don't serve any purpose,
but just make clutter. They make code harder to understand, not
easier.

Quote:
>main()

  Since the new version of the standard no longer accepts this, make
the return type explicit:

int main(void)

Quote:
> {
> int i=0, j=0, k=0, l=0;
> float temp, temps[20], postemps[20], negtemps[20];

  My compiler gave me the warning "Symbol 'temps' has been defined,
but not referenced" - cause: you have not used temps.

Quote:
> clrscr();

  My compiler gave me the warning "No prototype found for 'clrscr'" -
cause: using non-standard header & function. My compiler does come
with a conio.h, but it does not declare a function called clrscr().

Quote:
> cprintf("Please type in the temperatures\r\n");
> temp = in_float();
> cprintf("\r\n");
> while ((temp<=999.9) && (i<20));

  My compiler gave me the warning "Meaningless use of an expression" -
cause: semicolon on end of line.

Quote:
>  {
>  int(i) = temp;
>  i++;
>  temp = in_float();
>  cprintf("\r\n");
>  }
> for (j=0; j<i; j++)
>  {
>  if (i>=0)
>       {
>       i= postemps;

  My compiler gave me the error "Type mismatch" - cause: i is int,
postemps is array of float.

Quote:
>       }
>       else
>    {
>   i= negtemps;

  My compiler gave me the error "Type mismatch" - cause: i is int,
negtemps is array of float.

Quote:
>    }
>        }

> cprintf("The %i positive temperatures were:-\r\n",l);
> for (j=0; j<l; j++)
>  {
>  cprintf(" %f\r\n",postemps[j]);
>  }
> cprintf("The %i negative temperatures were:-\r\n",k);
> for (j=0; j>l; j--)
>  {
>  cprintf(" %f\r\n",negtemps[l]);
>  }

  Ick! What horrible indentation! Learn to indent code better. Proper
code layout makes it much easier to read and understand.

Quote:
> wait();

  No return value for main. FCOL, return something!

  return 0;

Quote:
> }
>/*
> * end of main()
> */

  Yes, we can see it's the end of main(). Please don't put such silly,
useless comments in your code. They don't serve any purpose, but just
make clutter. They make code harder to understand, not easier.

Quote:
>/*
> * function in_float()
> * ===================
> * inputs a floating-point number from the keyboard
> */

  You mean it returns a float set to a real number obtained from
standard input. Please make your comments reflect what is actually
going on, and try to keep it within the confines of the standard. (The
standard doesn't say anithing about keyboards. Standard input could be
coming from punched tape, punched cards, some other program, a WWW
server, a disk file or just about anithing else.)

Quote:
>float in_float(void)
> {
> char tbuff[12];
> float d;
> int i;

  My compiler gave me the warning "Symbol 'i' has been defined, but
not referenced" - cause: you have not used i.

Quote:
> tbuff[0] = 10;
> cgets(tbuff);
> sscanf(&tbuff[2],"%f",&d);
> return(d);
> }
>/*
> * end of in_float()
> */

  Yes, we can see it's the end of in_float(). Please don't put such
silly, useless comments in your code. They don't serve any purpose,
but just make clutter. They make code harder to understand, not
easier.

Quote:
>/*
> * function wait()
> * ===============
> * waits for a keypress
> */

  This comment could be smaller, instead of being so "chunky". This
just adds to the clutter. A 2 line comment really only requires 2
lines, not 5.

Quote:
>void wait(void)
> {
> cprintf("\r\nPress any key to terminate");
> getch();

  Two more non-standard functions.

Quote:
> }
>/*
> * end of wait()
> */

  Yes, we can see it's the end of wait(). Please don't put such silly,
useless comments in your code. They don't serve any purpose, but just
make clutter. They make code harder to understand, not easier.
--

----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
    http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============



Sat, 28 Sep 2002 03:00:00 GMT  
 Please Please Help!!!!!!

...[much other stuff snipped]

Quote:
> >/*
> > * function in_float()
> > * ===================
> > * inputs a floating-point number from the keyboard
> > */

>   You mean it returns a float set to a real number obtained from
> standard input. ... Standard input could be ...

Not necessarily.  The OP used cgets() which is nonstandard
but quite possibly uses the keyboard regardless of stdin.
fscanf or fgets + conversion would use stdin, and be portable.

But calling it a real number is not better.  The input will be
a decimal floating-point number, which has the same kind
of limitations as the usual (but not mandatory) internal
binary representation, i.e.,  a finite subset of the rationals.

Personally I think the name already says it inputs a floating-point
number, and no comment is needed at all.

--
- David.Thompson 1 now at worldnet.att.net



Wed, 02 Oct 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

2. PLEASE PLEASE HELP HELP...question on interleaving C functions

3. Please Please Help!!!!!!

4. simulate dragDrop of ListView Item -- Please Please Help!!!!

5. Very Urgent !!! please please help

6. PLEASE PLEASE HELP

7. Please Please Help! - pointer notation

8. Please please help a

9. Please please help a newbie!!

10. Please please help a newbie!!

11. Please, please help

12. About resizing ActiveMovie ActiveX control, please please help!

 

 
Powered by phpBB® Forum Software