This is my very first introduction to C++ and I am stuck with a very simple mini-calculator project. I cannot figure out what the errors are that the compiler is showing. I have shown my written code and the compiler messages below that. I am receiving syntax errors on the 'outfile' lines where I was asked to format the output. I would appreciate any help given. Thank you, thank you!!!

//Description: Create a mini calculator program that will allow user to enter 
//two integers [Operand 1 and Operand 2]; program will calculate sum, 
//difference, whole number quotient, remainder, real number quotient, square 
//root of Operand 1, and value of Operand 2 raised to the power of 4.

//**********Preprocessor Directives**********
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;

//**********main**********
int main(void)
{

int          choice,            //output choice
             op1,               //Operand 1
             op2,               //Operand 2
             sum,               //op1 + op2
             difference,        //op1 – op2
             product,           //op1 * op2
             w_quotient,        //op1/op2
             modulus,           //op1 % op2
             power;             //power
    
long double  r_quotient;        //op1/op2
             
double       y = 4,             //exponent
             sqrt(double op1),  //finds sqrt
             pow(double op1, double y);       //finds power
             
ofstream      outfile;         //to write to an output file


						  //input section
system ("cls");
cout << "Enter First Operand:  ";
cin >> op1;
cout << "Enter Second Operand:  ";
cin >> op2;
 

						  //process section

sum = op1 + op2;
difference = op1 - op2;
product = op1 * op2;
w_quotient = op1/op2;
modulus = op1 % op2;
r_quotient = op1/op2;
sqrt(op1);
pow(op2, 4);

						  //output section

system ("cls");
cout << "Output Choice: 1 (Screen) 2 (File), (choose 1 or 2: ";
cin >> choice;
if(choice==2)
   outfile.open("d.minicomputer.dta");
else
   outfile.open("con");
system ("cls");
outfile << setiosflags(ios::showpoint|ios::fixed)<< setprecision(2);
outfile << setw(49)"Mini Computer" << endl;
outfile << setw(49)"=============" << endl << endl;
outfile << setw(35)"Operand 1" setw(35)"Operand 2" endl;
outfile << setw(35)"=========" setw(35)"=========" endl << endl;
outfile << setw(35)op1 << setw(35)op2 << endl << endl;
outfile << setw(8)"Sum" setw(15)"Difference" setw(12)"Product" setw(19)"Whole Quotient" setw(14)"Remainder" endl;
outfile << setw(8)"===" setw(15)"==========" setw(12)"=======" setw(19)"==============" setw(14)"=========" endl << endl;
outfile << setw(8)sum << setw(15)difference << setw(12)product << setw(19) w_quotient << setw(14) modulus << endl << endl;
outfile << setw(15)"Real Quotient" setw(26)"Square Root of Operand 1" setw(29)"Operand 2 to the power of 4" endl;
outfile << setw(15)"=============" setw(26)"========================" setw(29)"===========================" endl << endl;
outfile << setw(15)r_quotient << setw(26)sqrt << setw(29)power << endl;
outfile.close();
return 0;
}

C O M P I L E R M E S S A G E

73 D:\minicalculator.cpp syntax error before string constant
77 D:\minicalculator.cpp syntax error before `<<' token


<< moderator edit: added [code][/code] tags >>

Oh, my.

outfile << setiosflags(ios::showpoint|ios::fixed)<< setprecision(2);
outfile << setw(49)<<"Mini Computer" << endl;
outfile << setw(49)<<"=============" << endl << endl;
outfile << setw(35)<<"Operand 1" <<setw(35)<<"Operand 2" <<endl;
outfile << setw(35)<<"=========" <<setw(35)<<"=========" <<endl << endl;
outfile << setw(35)<<op1 << setw(35)<<op2 << endl << endl;
outfile << setw(8)<<"Sum" <<setw(15)<<"Difference" <<setw(12)<<"Product" <<setw(19)<<"Whole Quotient" <<setw(14)<<"Remainder" <<endl;
outfile << setw(8)<<"===" <<setw(15)<<"==========" <<setw(12)<<"=======" <<setw(19)<<"==============" <<setw(14)<<"=========" <<endl << endl;
outfile << setw(8)<<sum << setw(15)<<difference << setw(12)<<product << setw(19) <<w_quotient << setw(14) <<modulus << endl << endl;
outfile << setw(15)<<"Real Quotient" <<setw(26)<<"Square Root of Operand 1" <<setw(29)<<"Operand 2 to the power of 4" <<endl;
outfile << setw(15)<<"=============" <<setw(26)<<"========================"<< setw(29)<<"===========================" <<endl << endl;
outfile << setw(15)<<r_quotient << setw(26)<<sqrt << setw(29)<<power << endl;

Thanks, Dave. You're the best! That worked! -R

Oh, my.

outfile << setiosflags(ios::showpoint|ios::fixed)<< setprecision(2);
outfile << setw(49)<<"Mini Computer" << endl;
outfile << setw(49)<<"=============" << endl << endl;
outfile << setw(35)<<"Operand 1" <<setw(35)<<"Operand 2" <<endl;
outfile << setw(35)<<"=========" <<setw(35)<<"=========" <<endl << endl;
outfile << setw(35)<<op1 << setw(35)<<op2 << endl << endl;
outfile << setw(8)<<"Sum" <<setw(15)<<"Difference" <<setw(12)<<"Product" <<setw(19)<<"Whole Quotient" <<setw(14)<<"Remainder" <<endl;
outfile << setw(8)<<"===" <<setw(15)<<"==========" <<setw(12)<<"=======" <<setw(19)<<"==============" <<setw(14)<<"=========" <<endl << endl;
outfile << setw(8)<<sum << setw(15)<<difference << setw(12)<<product << setw(19) <<w_quotient << setw(14) <<modulus << endl << endl;
outfile << setw(15)<<"Real Quotient" <<setw(26)<<"Square Root of Operand 1" <<setw(29)<<"Operand 2 to the power of 4" <<endl;
outfile << setw(15)<<"=============" <<setw(26)<<"========================"<< setw(29)<<"===========================" <<endl << endl;
outfile << setw(15)<<r_quotient << setw(26)<<sqrt << setw(29)<<power << endl;
This article has been dead for over six months. Start a new discussion instead.