Pleae help!!! Homework woes!

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 11
Reputation: rharvison is an unknown quantity at this point 
Solved Threads: 0
rharvison rharvison is offline Offline
Newbie Poster

Pleae help!!! Homework woes!

 
0
  #1
Mar 30th, 2005
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!!!

  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 >>
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Pleae help!!! Homework woes!

 
0
  #2
Mar 31st, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 11
Reputation: rharvison is an unknown quantity at this point 
Solved Threads: 0
rharvison rharvison is offline Offline
Newbie Poster

Re: Pleae help!!! Homework woes!

 
0
  #3
Apr 1st, 2005
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;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2175 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC