0

I am trying to print a hard copy of my code's output but I am not sure what t write in my code to have the output turn into a pdf or txt file right after it is displayed.

The code below is just a part of my whole project. This will generate the output that I want to display on my hardcopy.

float totaldinein()                                                         
//This function is to calculate the total price of DINING IN including the 5% government tax and 10% dining in charges.
{
    system("cls");
    printf("Select your payment method:1--> Cash Payment     2--> Credit Card Payment\n");
    scanf("%d",&t);

    switch (t)
    {
    case 1: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.15;                   
    //Calculation for grand total with government taxes,and cash payment.


                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
            printf("\nThe Total is $%.2f\n\n",total1);

            break;
    case 2: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.18;                   
            //Calculation for grand total with government taxes,and credit card payment.

                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
            printf("\nThe Total is $%.2f\n\n",total1);

            break;



    default: system("cls");
             printf("\nInvalid Error");
    }

}

float totaltakeout()                                                        
//This function is to calculate the  total price of TAKE AWAY including the 5% government tax and 5% dining in charges.
{
    system("cls");
    printf("Select your payment method:1--> Cash Payment     2--> Credit Card Payment\n");
    scanf("%d",&t);

    switch (t)
    {
        case 1: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.10;               
                //Calculation for grand total with government taxes,and cash payment.
                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
                printf("The Total is $%.2f\n\n",total1);

                break;



        case 2: total1 += (faj+taco+tost+chim+flau+burr+fried)*1.13;               
                //Calculation for grand total with government taxes,and credit card payment.

                printf("    Item                Price of 1     Total Price \n");
                printf("      Fajitas             8.00      $%.2f\n",faj);
                printf("      Tacos               5.00      $%.2f\n",taco);
                printf("       Tostadas            7.00      $%.2f\n",tost);
                printf("       Chimichanga         12.00      $%.2f\n",chim);
                printf("      Flautas             10.00      $%.2f\n",flau);
                printf("       Burrito             8.00      $%.2f\n",burr);
                printf("      Fried ice cream     5.00       $%.2f\n",fried);
                printf("The Total is $%.2f\n\n",total1);

                break;

        default: system("cls");
                 printf("\nInvalid Error");

    }
}
dbush
  • 205,898
  • 23
  • 218
  • 273
  • 1
    Possible duplicate of [Write to .txt file?](https://stackoverflow.com/questions/11573974/write-to-txt-file) – CloudPotato Jul 21 '19 at 16:48
  • Do you try to change your program to write into a file, or are you trying to use the same program in a way that the output (which normally ends on the console) ends up in a file? – Yunnosch Jul 21 '19 at 16:48
  • 2
    Did you try `myprogram > myoutput.txt` ? – Yunnosch Jul 21 '19 at 16:50
  • @Yunnosch I am trying to use to same program in a way that the output ends up in a file so I can print it. Like a receipt would be printed in a restaurant computer. – Sakshi Baldawa Jul 22 '19 at 20:24
  • And did you try? You did not accept the answer which basically copies my comment, so I assume you do not consider that helpful. So what is the problem with my proposal? In which way does it not solve your problem? – Yunnosch Jul 22 '19 at 20:41

1 Answers1

0

Just run your program program.exe, ./program.

But do this program > mytextfile on command line/from terminal.

Then all your programs output will be saved in the text file.

Doing the same thing within the program would be quite a bit more complicated but still doable.

Ace
  • 97
  • 8