-1

The question is :

Create a C program with a stub program code to calculate taxes?

void calculatetaxes (float gross, float deferred, float *fedtax,float *statetax,float *ssitax) ; //3.5 

float calcfedtax(float gross, float deferred); //3.5.1 
float calcstatetax (float fedtax) ; // 3.5.2 
float calcssitax (float gross, float deferred); //3.5.3

// stub program code
#include <stdio.h>
#define ADDR(var) &var

int main (void)
{
    float ft,st,ssit;

    calculatetaxes (1000, 100,ADDR(ft),ADDR(st),ADDR(ssit));

    printf(" fedtax = %8.2f\n",ft);
    printf(" StateTax = %8.2f\n",st); 
    printf(" ssitax = %8.2f\n",ssit);
    fflush(stdin); 
    getchar();
    return 0;
}

I am trying to make a code to calculate the fedtax,statetax, and ssitax for C and was wondering why my void for the stub program doesn't work and the #define addr(var) $var doesn't define my variables.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    Don't you mean to use `&` instead of `$` character ? – Mahesh Jul 01 '14 at 01:04
  • wow thank you!! did not see that part. -fixed it to & now just need to know know why void for my stub program doesn't work – user3792142 Jul 01 '14 at 01:09
  • What do you mean by "void" for your stub program? – timrau Jul 01 '14 at 01:12
  • when i run the code it says PCH warning: cannot find a suitable header stop location for void. i am new to c program and do not know why it is not working. – user3792142 Jul 01 '14 at 01:18
  • Why do you flush `stdin` here? That's not portable and I don't see a reason why you want to do so… – mafso Jul 01 '14 at 01:31
  • 1
    It's usually best to start small and simple, then build up. Get one function working before you attempt three. And is there a reason for the `ADDR` macro? Such macros are almost never a good idea. – Beta Jul 01 '14 at 01:32
  • @mafso My professor told me use use it. – user3792142 Jul 01 '14 at 01:38
  • @Beta Had to use it to define my variables – user3792142 Jul 01 '14 at 01:39
  • 3
    Just about the most pointless and obfuscatory macro ever. – Crowman Jul 01 '14 at 01:49
  • Is this a course specific to some platform? If it's only about C in general, your professor is just wrong and one of the causes of many bad C questions here and elsewhere. `stdin` and `stdout` are line-buffered and usually terminals are as well; if you don't want line-buffering, use `ncurses` or the like… And your `ADDR` macro is just stupid, don't use it, even if your professor told you so. It's like writing `ADD(a, b)` instead of `a+b` and defining a macro for that. – mafso Jul 01 '14 at 01:53
  • @mafso this class is a beginner class which is a formal introduction to the c programming language and well I can only learn what my professor teaches me, so I don't know many ways to do macros and looking up on the internet is harder as they use lots of codes I don't understand. – user3792142 Jul 01 '14 at 02:00
  • Never mind, I didn't intent to blame you; just be sceptical about what your professor says :) (and I think C is considered difficult mostly because of bad tutorials and teachers, not because of the language itself and I'm sometimes astonished by the mere mass of similar questions here and elsewhere just related to the same misinterpretation of the language, and not understanding buffering is one of the issues; anyway, that's not your actual problem here) – mafso Jul 01 '14 at 02:10
  • 1
    If your professor wants you to use the macro, use the macro; after you have passed the course and gotten your grade, you can discard these bad practices. – Beta Jul 01 '14 at 02:23
  • 1
    @PaulGriffiths I have seen `#define SPACE ' '` – M.M Jul 01 '14 at 04:43

1 Answers1

0

The lines

void calculatetaxes (float gross, float deferred, float *fedtax,float *statetax,float *ssitax) ; //3.5 
float calcfedtax(float gross, float deferred); //3.5.1 
float calcstatetax (float fedtax) ; // 3.5.2 
float calcssitax (float gross, float deferred); //3.5.3

are just declarations. They are not implementations. To provide stub implementations, you need to implement them, but not do anything in them.

void calculatetaxes (float gross, float deferred, float *fedtax,float *statetax,float *ssitax)
{
   // Implement this function but leave the others that do the main
   // calculations as stub implementations.
   *fedtax = calcfedtax(gross, deferred);
   *statetax = calcstatetax(*fedtax);
   *ssitax = calcssitax(gross, deferred);
}

float calcfedtax(float gross, float deferred)
{
   return 0.0f;
}

float calcstatetax (float fedtax)
{
   return 0.0f;
}

float calcssitax (float gross, float deferred)
{
   return 0.0f;
}
R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • @user3792142: You should also change the `*` in your `printf` statement to `%` (maybe it's just a typo, I'm not sure). – mafso Jul 01 '14 at 01:30
  • i changed my stub to your code, and ran it but why do I get negative numbers. – user3792142 Jul 01 '14 at 01:31
  • @user3792142: You use uninitialized values. Anything could happen, even negative numbers. – mafso Jul 01 '14 at 01:58
  • @mafso is this a good initialization of the values #define FEDTAXRATE 0.15 #define STATETAXRATE 0.07 #define SSITAXRATE 0.0775 – user3792142 Jul 01 '14 at 02:06
  • @mafso nevermind changing the values of my floats ft,st, and ssit was the problem here – user3792142 Jul 01 '14 at 02:11
  • @user3792142: The `calculatetaxes()` stub body should perhaps be `{ *fedtax = calcfedtax(gross, deferred); *statetax = calcstatetax(fedtax); *ssitax = calcssitax(gross, deferred); }`. That way, the returned values are initialized (to `0.0`). – Jonathan Leffler Jul 01 '14 at 03:00
  • @JonathanLeffler, like that suggestion. Updated the answer. – R Sahu Jul 01 '14 at 03:39