Gibson486
Lifer
This program is written to compute volume of two pyramids with a retangular base, however, the output file will not output right. It inputs zeroes instead of teh number i entered while the code runs.
#include <fstream>
#include <iostream>
#define HEIGHT 7 /* make HEIGHT A REAL */
using namespace std; /*cin and cout stored in the standard library*/
int main (void)
{
double side1,side2,volume;
FILE *outp;
outp=fopen("a: Pryamid.out","w");/*old way! open an output filr to save results*/
ofstream outfile; /*new way! varaible outfile to write a file*/
outfile.open("a: output.txt");/*open output to write*/
printf("ENTER LENGTH OF TWO BASES : ");
scanf("%lf %lf",&side1,&side2); /*l=lowecase L*/
fprintf(outp,"Height is %f, base side lengths are %f and %f \n\n",HEIGHT,side1,side2);
/*line writes output file*/
outfile <<"Height is "<<HEIGHT <<", base side lengths are "<< side1 <<" and "<< side2 <<"\n"; volume=side1*side2*HEIGHT/3.;
/*stop typing*/
printf("Pryamid volume is %f cubic cm\n",volume);
fprintf(outp,"Pryamid volume is %f cubic cm \n\n",volume);
/*C++ function to print to screen*/
cout << "ENTER NEW LENGTHS OF TWO BASE SIDES :" << endl;
/* C++ function to read in values for side1 and side2 */
cin >> side1 >> side2;
fprintf(outp,"Height is %f, base side lengths are %f and %f \n\n",
HEIGHT,side1,side2);
volume=side1*side2*HEIGHT/3.;
cout << "Pyramid volume is "<< volume << " cubic cm\n";
fprintf(outp,"Pyramid volume is %5.3f cubic cm\n\n",volume);
return 0;
}
edit: space put after "a:" to prevent face icons
#include <fstream>
#include <iostream>
#define HEIGHT 7 /* make HEIGHT A REAL */
using namespace std; /*cin and cout stored in the standard library*/
int main (void)
{
double side1,side2,volume;
FILE *outp;
outp=fopen("a: Pryamid.out","w");/*old way! open an output filr to save results*/
ofstream outfile; /*new way! varaible outfile to write a file*/
outfile.open("a: output.txt");/*open output to write*/
printf("ENTER LENGTH OF TWO BASES : ");
scanf("%lf %lf",&side1,&side2); /*l=lowecase L*/
fprintf(outp,"Height is %f, base side lengths are %f and %f \n\n",HEIGHT,side1,side2);
/*line writes output file*/
outfile <<"Height is "<<HEIGHT <<", base side lengths are "<< side1 <<" and "<< side2 <<"\n"; volume=side1*side2*HEIGHT/3.;
/*stop typing*/
printf("Pryamid volume is %f cubic cm\n",volume);
fprintf(outp,"Pryamid volume is %f cubic cm \n\n",volume);
/*C++ function to print to screen*/
cout << "ENTER NEW LENGTHS OF TWO BASE SIDES :" << endl;
/* C++ function to read in values for side1 and side2 */
cin >> side1 >> side2;
fprintf(outp,"Height is %f, base side lengths are %f and %f \n\n",
HEIGHT,side1,side2);
volume=side1*side2*HEIGHT/3.;
cout << "Pyramid volume is "<< volume << " cubic cm\n";
fprintf(outp,"Pyramid volume is %5.3f cubic cm\n\n",volume);
return 0;
}
edit: space put after "a:" to prevent face icons