944,045 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2504
  • C++ RSS
Mar 30th, 2005
0

Pleae help!!! Homework woes!

Expand Post »
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++ Syntax (Toggle Plain Text)
  1. //Description: Create a mini calculator program that will allow user to enter
  2. //two integers [Operand 1 and Operand 2]; program will calculate sum,
  3. //difference, whole number quotient, remainder, real number quotient, square
  4. //root of Operand 1, and value of Operand 2 raised to the power of 4.
  5.  
  6. //**********Preprocessor Directives**********
  7. #include <fstream>
  8. #include <iostream>
  9. #include <stdio.h>
  10. #include <iomanip>
  11. #include <cmath>
  12. #include <math.h>
  13. #include <string>
  14. using namespace std;
  15.  
  16. //**********main**********
  17. int main(void)
  18. {
  19.  
  20. int choice, //output choice
  21. op1, //Operand 1
  22. op2, //Operand 2
  23. sum, //op1 + op2
  24. difference, //op1 – op2
  25. product, //op1 * op2
  26. w_quotient, //op1/op2
  27. modulus, //op1 % op2
  28. power; //power
  29.  
  30. long double r_quotient; //op1/op2
  31.  
  32. double y = 4, //exponent
  33. sqrt(double op1), //finds sqrt
  34. pow(double op1, double y); //finds power
  35.  
  36. ofstream outfile; //to write to an output file
  37.  
  38.  
  39. //input section
  40. system ("cls");
  41. cout << "Enter First Operand: ";
  42. cin >> op1;
  43. cout << "Enter Second Operand: ";
  44. cin >> op2;
  45.  
  46.  
  47. //process section
  48.  
  49. sum = op1 + op2;
  50. difference = op1 - op2;
  51. product = op1 * op2;
  52. w_quotient = op1/op2;
  53. modulus = op1 % op2;
  54. r_quotient = op1/op2;
  55. sqrt(op1);
  56. pow(op2, 4);
  57.  
  58. //output section
  59.  
  60. system ("cls");
  61. cout << "Output Choice: 1 (Screen) 2 (File), (choose 1 or 2: ";
  62. cin >> choice;
  63. if(choice==2)
  64. outfile.open("d.minicomputer.dta");
  65. else
  66. outfile.open("con");
  67. system ("cls");
  68. outfile << setiosflags(ios::showpoint|ios::fixed)<< setprecision(2);
  69. outfile << setw(49)"Mini Computer" << endl;
  70. outfile << setw(49)"=============" << endl << endl;
  71. outfile << setw(35)"Operand 1" setw(35)"Operand 2" endl;
  72. outfile << setw(35)"=========" setw(35)"=========" endl << endl;
  73. outfile << setw(35)op1 << setw(35)op2 << endl << endl;
  74. outfile << setw(8)"Sum" setw(15)"Difference" setw(12)"Product" setw(19)"Whole Quotient" setw(14)"Remainder" endl;
  75. outfile << setw(8)"===" setw(15)"==========" setw(12)"=======" setw(19)"==============" setw(14)"=========" endl << endl;
  76. outfile << setw(8)sum << setw(15)difference << setw(12)product << setw(19) w_quotient << setw(14) modulus << endl << endl;
  77. outfile << setw(15)"Real Quotient" setw(26)"Square Root of Operand 1" setw(29)"Operand 2 to the power of 4" endl;
  78. outfile << setw(15)"=============" setw(26)"========================" setw(29)"===========================" endl << endl;
  79. outfile << setw(15)r_quotient << setw(26)sqrt << setw(29)power << endl;
  80. outfile.close();
  81. return 0;
  82. }




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 >>
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
rharvison is offline Offline
11 posts
since Feb 2005
Mar 31st, 2005
0

Re: Pleae help!!! Homework woes!

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;
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Apr 1st, 2005
0

Re: Pleae help!!! Homework woes!

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

Quote 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;
Reputation Points: 11
Solved Threads: 0
Newbie Poster
rharvison is offline Offline
11 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Dynamic arrays inside a class?
Next Thread in C++ Forum Timeline: please help me to rewrite this.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC