Home > Software design >  How can I get printf to display a calculation the computer performed earlier?
How can I get printf to display a calculation the computer performed earlier?

Time:10-08

What I'm having trouble doing is figuring out how to make a simple calculator in which I input hours, PRO_H, PRE_H, etc, and then using fixed rates, PRO_R, PRE_R, etc, to calculate how much money was owed. I would just like the printf() function at the end to output the calculation the code will perform. I'm not sure if my format would work for the multiplication, though.

#include <cstdio>

int main()
{
    int PRO_R =100;
    int PRE_R =60;
    int PROD_R =40;

    int PRO_H =0;
    int PRE_H =0;
    int PROD_H =0;

// Do I need to declare these as intergers for calculations?

    int PRO_C =PRO_H * PRO_R;
    int PRE_C =PRE_H * PRE_R;
    int PROD_C =PROD_C * PRE_R;
    int TOT_C =PRO_C   PRE_C   PROD_C;

    printf("Enter Production Hours:\n");
    scanf("%d", &PRO_H);

    printf("Enter Pre-Production Hours:\n");
    scanf("%d", &PRE_H);

    printf("Enter Producer's Hours:\n");
    scanf("%d", &PROD_H);

// These are the calculations below in which I need to get outputted. So the I would like the total cost, PRO_C, to equal the PRO_H times the PRO_R. 

    PRO_C =(PRO_H * PRO_R);
    PRE_C =(PRE_H * PRE_R);
    PROD_C =(PROD_H * PROD_H);
    TOT_C =(PRO_C   PRE_C   PROD_C);

    printf("Production cost:");

    return 0;
}

CodePudding user response:

I'm assuming that you want something like this printed out? Is that right? You just do "%d" in the spot that you want to display your integer and outside the quotes you put a comma and the integer you wanted to print.

// These are the calculations below in which I need to get outputted. So the I would like the total cost, PRO_C, to equal the PRO_H times the PRO_R. 

PRO_C =(PRO_H * PRO_R);
PRE_C =(PRE_H * PRE_R);
PROD_C =(PROD_H * PROD_H);
TOT_C =(PRO_C   PRE_C   PROD_C);


printf("Production cost: %d", TOT_C);
  •  Tags:  
  • c
  • Related