1

This is my main module. I have a few external modules.

int main(void)
{
    char ln[15+1];
    char fn[10+1];
    float fed,state,ssi;
    float g,h,p,d,n;

    InputEmployeeData(&ln[0],&fn[0],&h,&p,&d); // call 3.3
    CalculateGross(h,p, &g); // call 3.4
    computeTaxes(g,d,ADDR(fed),ADDR(state),ADDR(ssi)); // call 3.5
    n = g-fed-state-ssi-d;
    printf("  Fed   =   %8.2f\n",fed);
    printf("  State =   %8.2f\n",state);
    printf("  SSI   =   %8.2f\n",ssi);
    printf("  Net   =   %8.2f\n",n);
    while(getchar() != '\n'); // flush(stdin)
    return 0;

main.cpp using iostream

cout << "  Fed   =   %8.2f\n" << fed;
cout << "  State =   %8.2f\n" << state;
cout << "  SSI   =   %8.2f\n" << ssi;
cout << "  Net   =   %8.2f\n" << n;
 cin.sync();
//while(getchar() != '\n'); 
// flush(stdin)
return 0;

inputemployeedata.cpp using stdio.h

//3.3
#include <stdio.h>
#define ADDR(var) &var

void InputEmployeeData(char *lastname,char *firstname, // 3.3
                       float *hours,float *payrate, float *defr);

void InputEmployeeData(char *lastname,char *firstname, // 3.3
                       float *hours,float *payrate, float *defr)
{
    printf(" Enter the name ==> ");
    scanf("%s%s",firstname,lastname);
    printf(" Enter the hours and payrate ==> ");
    scanf("%f%f",hours,payrate);
    printf("  Enter the deferred earning amount ==> ");
    scanf("%f",defr);
}

inputemployeedata.cpp using iostream

{
    cout << " Enter the name ==> ";
    cin >> *firstname >> *lastname;
    cout <<" Enter the hours and payrate ==> ";
    cin >> *hours >> *payrate;
    cout << "  Enter the deferred earning amount ==> ";
    cin >> *defr;

I Don't know the equivalent of %8.2f for cout. I'm just stuck enter image description here

MD XF
  • 7,860
  • 7
  • 40
  • 71
  • 1
    http://stackoverflow.com/a/11989420/1517864 this should help – jayant Oct 12 '15 at 20:07
  • Docs + examples: http://www.cplusplus.com/reference/ios/fixed/ – donjuedo Oct 12 '15 at 20:09
  • Why not just sprintf the floating point numbers into local char buffers, then cout those buffers? You can keep the same printf formatting while still using iostream for the file IO. Or better yet, make a function that does the printf into its own local buffer and returns a std::string, then call that function inline in the cout line. – Dan Korn Oct 12 '15 at 20:24

1 Answers1

-1

C: printf a float value

TL;DR : %f denotes a float being printed. %8.2f denotes total characters are 8 (or any other number before the dot in "%8.2f"), and 2 (or any other number after the dot in the %f command) after the dot.

In this case, a number such as "12345.78" may be printed.

Wuh? But 8 numbers! No, characters. The dot is included in the total count.

Hope this helps!

Community
  • 1
  • 1
Adolphin
  • 62
  • 4
  • 1
    How does this answer how to convert a `printf()` call to `cout`? – NathanOliver Oct 12 '15 at 20:17
  • 4
    The question could have three meanings. The first: the OP knows all the printf options, but is having trouble finding the iostream equivalent. The second: the OP knows all the iostream options, but doesn't understand printf's options. The third: the OP knows neither the printf options nor the iostream ones. This is a correct and useful answer for the second interpretation, but *only* for the second interpretation, it's useless for the other two. And I don't think that second interpretation is the right one. –  Oct 12 '15 at 20:20