Help with c homework 
Author Message
 Help with c homework

I am getting the error Type mismatch in redeclaration of 'min_work'
in my c programing home work and I can not figure out what I did
wrong.

Also in the assignment my teacher asked to make one function 'untyped'
I can not find this in my book and do not know how to do it.

Thanks for helping out a neophyte,
awzse

Bad example of programming attached:

========================================

/* awzse                        parking.c                02-27-02
This program will calculate the amount of money due for parking
time.

*/
#include <stdio.h>
#define HRMIN 60
int min_work (void);
int header (void);
int fee_finder (int tot);
int main (void)
{
        int tot_time, /*total time in minutes*/
            tot_hr,   /*total hours*/
            tot_min;  /*total minutes*/
     double fee;      /*total fee*/
       char ampm_in,  /*ampm in*/
            ampm_out; /*ampm out*/

            printf("The Down-Town Parking Garage\n");
            tot_time = min_work();
            tot_hr = tot_time / HRMIN;
            tot_min = tot_time % HRMIN;
            printf("%l:%l     ", tot_hr, tot_min);
            fee_finder(tot_time);

     return(0);

Quote:
}

int min_work
{       int hr_in,     /*(hours) time in     */
            min_in,    /*(minutes) time in   */
            tot_in,    /*(minutes total in   */
            hr_out,    /*(hours) time out    */
            min_out,   /*(minutes) time out  */
            tot_out;   /*(minutes) total out */
       char ampm_in,   /*AM or PM time in    */
            ampm_out;  /*AM or PM time out   */

        printf("Enter Time in as: Hr Min>");
         scanf("%d%d", &hr_in &min_in);
        printf("\nEnter A if AM, P if PM>");
         scanf("%c", ampm_in);
        printf("\nEnter Time Out as: Hr Min>");
         scanf("%d%d", &hr_out &min_out);
        printf("\nEnter A if AM, P if PM>");
         scanf("%c", &ampm_out);

        header();
        printf("%f:%f %cM" hr_in, min_in, ampm_in);
        printf("     %f:%f %cM" hr_out, min_out, ampm_out);

        if(ampm_in == 'P' || 'p') hr_in + 12;
        if(ampm_out == 'P' || 'p') hr_out + 12;
        tot_in = hr_in * HRMIN + min_in;
        tot_out = hr_out * HRMIN + min_out;
        tot_in = tot_in - tot_out;

        return(tot_in);

Quote:
}

int header(void)
{
        printf("\nTime In     Time Out     ");
        printf("Total Time     Fee");
        printf("-------     --------     ");
        printf("-----------     ------");

        return(0);

Quote:
}

int fee_finder (tot)
{
        tot = tot / HRMIN
        if(tot =< 1) printf("$6.00");
         else if(tot =< 2) printf("$10.50");
          else if(tot =< 3) printf("$15.00");
           else if(tot =< 4) printf("$19.50");
            else if(tot =< 5) printf("$24.00");
             else if(tot =< 6) printf("$28.50");
              else if(tot =< 7) printf("$33.00");
               else if)tot =< 8) printf("$37.50");
                else printf("$40.00")
        return(0)
Quote:
}



Sun, 29 Aug 2004 00:15:51 GMT  
 Help with c homework

Quote:
awze writes:
> I am getting the error Type mismatch in redeclaration of 'min_work'
> in my c programing home work and I can not figure out what I did
> wrong.

> Also in the assignment my teacher asked to make one function 'untyped'
> I can not find this in my book and do not know how to do it.

My guess is that he means a function that returns a void.

Quote:
> ========================================

> /* awzse                        parking.c                02-27-02
> This program will calculate the amount of money due for parking
> time.

> */
> #include <stdio.h>
> #define HRMIN 60
> int min_work (void);
> int header (void);
> int fee_finder (int tot);
> int main (void)
> {
>         int tot_time, /*total time in minutes*/
>             tot_hr,   /*total hours*/
>             tot_min;  /*total minutes*/
>      double fee;      /*total fee*/
>        char ampm_in,  /*ampm in*/
>             ampm_out; /*ampm out*/

>             printf("The Down-Town Parking Garage\n");
>             tot_time = min_work();
>             tot_hr = tot_time / HRMIN;
>             tot_min = tot_time % HRMIN;
>             printf("%l:%l     ", tot_hr, tot_min);
>             fee_finder(tot_time);

>      return(0);
> }

> int min_work

Does this look like the prototype?  No.

<snip>



Sun, 29 Aug 2004 00:43:48 GMT  
 Help with c homework
First off, please try to cut'n'paste, or otherwise provide a verbatum copy
of your source code. I know you didn't do that here, 'cause this code has
more problems than just the one you indicated.

Quote:

>I am getting the error Type mismatch in redeclaration of 'min_work'
>in my c programing home work and I can not figure out what I did
>wrong.

>Also in the assignment my teacher asked to make one function 'untyped'
>I can not find this in my book and do not know how to do it.

>Thanks for helping out a neophyte,
>awzse

>Bad example of programming attached:

>========================================

>/* awzse                        parking.c                02-27-02
>This program will calculate the amount of money due for parking
>time.

>*/
>#include <stdio.h>
>#define HRMIN 60
>int min_work (void);

               /
Look here ----'

- Show quoted text -

Quote:
>int header (void);
>int fee_finder (int tot);
>int main (void)
>{
>        int tot_time, /*total time in minutes*/
>            tot_hr,   /*total hours*/
>            tot_min;  /*total minutes*/
>     double fee;      /*total fee*/
>       char ampm_in,  /*ampm in*/
>            ampm_out; /*ampm out*/

>            printf("The Down-Town Parking Garage\n");
>            tot_time = min_work();
>            tot_hr = tot_time / HRMIN;
>            tot_min = tot_time % HRMIN;
>            printf("%l:%l     ", tot_hr, tot_min);

                     == ==
Reread your docn on printf() format characters, and rewrite this line

Quote:
>            fee_finder(tot_time);

>     return(0);
>}

>int min_work

             /
Look here --'

Now, tell me what's missing here.

Quote:
>{       int hr_in,     /*(hours) time in     */
>            min_in,    /*(minutes) time in   */
>            tot_in,    /*(minutes total in   */
>            hr_out,    /*(hours) time out    */
>            min_out,   /*(minutes) time out  */
>            tot_out;   /*(minutes) total out */
>       char ampm_in,   /*AM or PM time in    */
>            ampm_out;  /*AM or PM time out   */

>        printf("Enter Time in as: Hr Min>");

If this is buffered (and interactive exchanges usually are), it won't be
displayed until you either
  a) print a newline character, or
  b) fflush(stdout)

Until then, the user doesn't get to see your prompt.

Quote:
>         scanf("%d%d", &hr_in &min_in);

What happens if the user types in
   X
and hits return?

Quote:
>        printf("\nEnter A if AM, P if PM>");
>         scanf("%c", ampm_in);

See above

Quote:
>        printf("\nEnter Time Out as: Hr Min>");
>         scanf("%d%d", &hr_out &min_out);

See above

Quote:
>        printf("\nEnter A if AM, P if PM>");
>         scanf("%c", &ampm_out);

See above

Quote:

>        header();
>        printf("%f:%f %cM" hr_in, min_in, ampm_in);

                 == ==

Have you reread the section on printf() format strings yet?

Quote:
>        printf("     %f:%f %cM" hr_out, min_out, ampm_out);

                      == ==
See above

Hmmm, headings and data, all on one line (you don't expect to read the
printed output, do you?)

Quote:

>        if(ampm_in == 'P' || 'p') hr_in + 12;

Your if() statement will always add 12 to hr_in.
Now, you tell me why.

Quote:
>        if(ampm_out == 'P' || 'p') hr_out + 12;

Same here

Quote:
>        tot_in = hr_in * HRMIN + min_in;
>        tot_out = hr_out * HRMIN + min_out;
>        tot_in = tot_in - tot_out;

>        return(tot_in);
>}

>int header(void)
>{
>        printf("\nTime In     Time Out     ");
>        printf("Total Time     Fee");
>        printf("-------     --------     ");
>        printf("-----------     ------");

All on one line, eh?

And remember, you've got data on this line as well (see where header() is
called).

Quote:

>        return(0);
>}

>int fee_finder (tot)
>{
>        tot = tot / HRMIN

                          /
Nope --------------------'   (typo, I bet)

Quote:
>        if(tot =< 1) printf("$6.00");
>         else if(tot =< 2) printf("$10.50");
>          else if(tot =< 3) printf("$15.00");
>           else if(tot =< 4) printf("$19.50");
>            else if(tot =< 5) printf("$24.00");
>             else if(tot =< 6) printf("$28.50");
>              else if(tot =< 7) printf("$33.00");
>               else if)tot =< 8) printf("$37.50");

                      /
Nope ----------------'   (a different typo, this time)

Quote:
>                else printf("$40.00")

                                      /
Nope  -------------------------------'  (another typo, I bet)

Why didn't you use a switch()/case statement?

Quote:
>        return(0)

                  /
Nope ------------'   (again with the typo, I bet)

Quote:
>}

Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employer's.)



Sun, 29 Aug 2004 00:42:05 GMT  
 Help with c homework

Quote:

>  I am getting the error Type mismatch in redeclaration of 'min_work'
>  in my c programing home work and I can not figure out what I did
>  wrong.

Compare this:

Quote:
>  int min_work (void);

with this:

Quote:
>  int min_work

The latter is missing (void).

Quote:
>  int fee_finder (tot)
>  {
>          tot = tot / HRMIN
>          if(tot =< 1) printf("$6.00");
>           else if(tot =< 2) printf("$10.50");
>            else if(tot =< 3) printf("$15.00");
>             else if(tot =< 4) printf("$19.50");
>              else if(tot =< 5) printf("$24.00");
>               else if(tot =< 6) printf("$28.50");
>                else if(tot =< 7) printf("$33.00");
>                 else if)tot =< 8) printf("$37.50");
>                  else printf("$40.00")

There are several better ways to accomplish this. You could use a
switch or an array, for instance.
If you insist on using an if-else ladder, use the == operator where
it makes more sense than =<. Also, many people prefer it if the
ladder is not indented.

Quote:
>          return(0)

You're missing a semicolon here. Also, the parentheses are not
needed, but that's just a style issue.
Judging from the syntax errors in this code, this might not be the
code you actually tried to compile; that's not good. If you don't
show us the original code, the differences between it and the posted
version will hide important details or just be confusing.

Quote:
>  Also in the assignment my teacher asked to make one function 'untyped'
>  I can not find this in my book and do not know how to do it.

There is no such thing. Maybe he meant a function with return type
void. Ask him what exactly he meant.

Gergo
--
"... we define the quality factor Q_p as the ratio of the resistance
to the reactance of the inductance at resonance."
-- Allan R. Hambley, "Electrical Engineering: Principles and Applications"



Sun, 29 Aug 2004 00:47:45 GMT  
 Help with c homework
: int min_work (void);
^^^^^^^^
Here is the prototype.

Here is the definition:
: int min_work
: {       int hr_in,     /*(hours) time in     */
:             min_in,    /*(minutes) time in   */
:             tot_in,    /*(minutes total in   */
:             hr_out,    /*(hours) time out    */
:             min_out,   /*(minutes) time out  */
:             tot_out;   /*(minutes) total out */
:        char ampm_in,   /*AM or PM time in    */
:             ampm_out;  /*AM or PM time out   */

You don't have any parentheses in the function definition.
Try
int min_work(void)
{

:         printf("Enter Time in as: Hr Min>");
:          scanf("%d%d", &hr_in &min_in);
:         printf("\nEnter A if AM, P if PM>");
:          scanf("%c", ampm_in);
:         printf("\nEnter Time Out as: Hr Min>");
:          scanf("%d%d", &hr_out &min_out);
:         printf("\nEnter A if AM, P if PM>");
:          scanf("%c", &ampm_out);

:         header();
:         printf("%f:%f %cM" hr_in, min_in, ampm_in);
:         printf("     %f:%f %cM" hr_out, min_out, ampm_out);

:         if(ampm_in == 'P' || 'p') hr_in + 12;
:         if(ampm_out == 'P' || 'p') hr_out + 12;
:         tot_in = hr_in * HRMIN + min_in;
:         tot_out = hr_out * HRMIN + min_out;
:         tot_in = tot_in - tot_out;

:         return(tot_in);
: }

I don't know what your teacher meant by 'untyped', maybe a function
which returns void?
void min_work( void )?

By the way, don't use scanf(), see the comp.lang.c FAQ for some good hints,
especially question 12.20.

Good Luck,

Paul

--
Paul D. Boyle

North Carolina State University
http://laue.chem.ncsu.edu/web/xray.welcome.html



Sun, 29 Aug 2004 00:49:58 GMT  
 Help with c homework

Quote:

... snip ...

> Also in the assignment my teacher asked to make one function 'untyped'
> I can not find this in my book and do not know how to do it.

There is no such thing as an untyped function in C.  There are
void functions which return no value.  I think your teacher needs
instruction.

--

   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)



Sun, 29 Aug 2004 04:18:32 GMT  
 Help with c homework

Quote:

> I am getting the error Type mismatch in redeclaration of 'min_work'
> in my c programing home work and I can not figure out what I did
> wrong.

> Also in the assignment my teacher asked to make one function 'untyped'
> I can not find this in my book and do not know how to do it.

I assume she meant

  void foo(int arbitrary);

...she'd better not have meant

  foo(int arbitrary);

At any rate, "untyped" is not strictly possible, and so was a
misleading way of stating whatever she meant.

Quote:
> /* awzse                        parking.c                02-27-02
> This program will calculate the amount of money due for parking
> time.

> */
> #include <stdio.h>
> #define HRMIN 60
> int min_work (void);
> int header (void);
> int fee_finder (int tot);
> int main (void)
> {
>         int tot_time, /*total time in minutes*/
>             tot_hr,   /*total hours*/
>             tot_min;  /*total minutes*/
>      double fee;      /*total fee*/
>        char ampm_in,  /*ampm in*/
>             ampm_out; /*ampm out*/

>             printf("The Down-Town Parking Garage\n");
>             tot_time = min_work();
>             tot_hr = tot_time / HRMIN;
>             tot_min = tot_time % HRMIN;
>             printf("%l:%l     ", tot_hr, tot_min);
>             fee_finder(tot_time);

>      return(0);
> }

Interesting, and somewhat aesthetic indentation you've got going.
Does your editor automatically format it like that, or did you
painstakingly insert all those spaces yourself?

Kinda breaks down, though, when you start using types like:

  struct an_arbitrarily_but_sufficiently_long_tag

(Doesn't even have to be near that big).

Quote:
> int min_work
> {       int hr_in,     /*(hours) time in     */

Here's your problem.  You forgot to include the parameters list in
your function declaration.  What you've written here isn't legal
syntax.  You want:

  int min_work(void)
  {

- Show quoted text -

Quote:
>             min_in,    /*(minutes) time in   */
>             tot_in,    /*(minutes total in   */
>             hr_out,    /*(hours) time out    */
>             min_out,   /*(minutes) time out  */
>             tot_out;   /*(minutes) total out */
>        char ampm_in,   /*AM or PM time in    */
>             ampm_out;  /*AM or PM time out   */

>         printf("Enter Time in as: Hr Min>");
>          scanf("%d%d", &hr_in &min_in);
>         printf("\nEnter A if AM, P if PM>");
>          scanf("%c", ampm_in);
>         printf("\nEnter Time Out as: Hr Min>");
>          scanf("%d%d", &hr_out &min_out);
>         printf("\nEnter A if AM, P if PM>");
>          scanf("%c", &ampm_out);

Many systems may not have finished printing your prompts out to the
screen/terminal/whatever before scanf() kicks in expecting input.  To
solve, this, add

  fflush(stdout);

before each call to scanf().

<snip>

Quote:
> int fee_finder (tot)

Make sure to make this:

  int fee_finder (int tot)

the way you have it is legal, but deprecated - it doesn't specify
tot's type, which luckily enough defaulted to int.  But this makes it
unprototyped.

Quote:
> {
>         tot = tot / HRMIN
>         if(tot =< 1) printf("$6.00");
>          else if(tot =< 2) printf("$10.50");
>           else if(tot =< 3) printf("$15.00");
>            else if(tot =< 4) printf("$19.50");
>             else if(tot =< 5) printf("$24.00");
>              else if(tot =< 6) printf("$28.50");
>               else if(tot =< 7) printf("$33.00");
>                else if)tot =< 8) printf("$37.50");
>                 else printf("$40.00")

C has no =< operator - it's <=.  Also, that operator shouldn't be used
in this case - if you get to the first else block, you *know* it can't
be less than 2, and so on.

Are these values arbitrary, or is there some formula behind there
choice?  If the latter, you should use that instead of hardcoding
arbitrary values.  Also, use a switch statement instead of if/else, if
possible; use a variable to store the resulting number (double,
maybe?)  and print that using a single printf().

Quote:
>         return(0)
> }

You do know that return is an operator, not a function, right?

  return 0;  /* you forgot the semicolon here, too */

HTH,
-Micah



Sun, 29 Aug 2004 16:19:20 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. help with java homework

2. help: process management homework

3. I NEED HELP WITH MY HOMEWORK AGAIN!!!

4. Need help with C homework

5. Can you help with my homework?

6. Help with c homework (again)

7. homework help

8. Homework Help

9. HELP! Homework re:Strings

10. homework help scanning info from disk?

11. Help woth homework due tonight.

12. I will pay for homework help !HELLLPPPP !!!HELLLPPPP !!!

 

 
Powered by phpBB® Forum Software