我正在尝试打印代码输出的硬拷贝,但我不确定在代码中写入什么才能使输出在显示后立即变成 pdf 或 txt 文件。
下面的代码只是我整个项目的一部分。这将生成我想要在硬拷贝上显示的输出。
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");
}
}
最佳答案
只需运行您的程序program.exe,./program。
但是在命令行/终端上执行此程序 > mytextfile。
然后您的所有程序输出都将保存在文本文件中。
在程序中做同样的事情会复杂一些,但仍然可行。
关于c - 如何将代码的输出重定向到代码块中的 pdf 或文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57135081/