| | |
Pleae help!!! Homework woes!
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2005
Posts: 11
Reputation:
Solved Threads: 0
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!!!
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 [/COLOR]
<< moderator edit: added [code][/code] tags >>
C++ Syntax (Toggle Plain Text)
//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 [/COLOR]
<< 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;
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Feb 2005
Posts: 11
Reputation:
Solved Threads: 0
Thanks, Dave. You're the best! That worked! -R
•
•
•
•
Originally Posted by Dave Sinkula
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;
![]() |
Similar Threads
- We only give homework help to those who show effort (Computer Science)
- Need help with Computer Science homework (Computer Science)
- Please help... Homework woes! (C++)
Other Threads in the C++ Forum
- Previous Thread: Dynamic arrays inside a class?
- Next Thread: please help me to rewrite this.
Views: 2175 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






