944,110 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1025
  • C++ RSS
Oct 23rd, 2007
0

Check my code, There is 1 error, cant find it

Expand Post »
I tried to write a basic calculator program, Visual basic finds 1 error. I cant find it.
Please help. I am kind off new to programming.

c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(void)
  5. {
  6. system("TITLE calculator");
  7. system("COLOR 9");
  8. char cChar;
  9. double dfirstnumber;
  10. double dsecondnumber;
  11. char cDoagain;
  12.  
  13. do
  14. {
  15. system("CLS");
  16. cout << "please enter the first number that you would like to use" << endl;
  17. cin >> dfirstnumber;
  18.  
  19. cout << "please enter the operation that you would like to complete" << " (+,-,* or /) " << endl;
  20. cin >> cChar;
  21.  
  22. cout << "please enter the second number you would like to use" << endl;
  23. cin >> dsecondnumber;
  24.  
  25. switch (cChar)
  26. {
  27. case '+':
  28. cout << " the answer is: " << dfirstnumber << " + " << dsecondnumber << " = " <<
  29. (dfirstnumber + dsecondnumber) << endl;
  30. break;
  31.  
  32. case '-':
  33. cout << "the answer is: " << dfirstnumber << " - " << dsecondnumber << " = " <<
  34. (dfirstnumber - dsecondnumber) << endl;
  35. break;
  36.  
  37. case '*':
  38. cout << "the answer is: " << dfirstnumber << " * " << dsecondnumber << " = " <<
  39. (dfirstnumber * dsecondnumber) << endl;
  40. break;
  41. case 'X':
  42. cout << "the answer is: " << dfirstnumber << " X " << dsecondnumber << " = " <<
  43. (dfirstnumber * dsecondnumber) << endl;
  44. break;
  45. case 'x':
  46. cout << "the answer is: " << dfirstnumber << " x " << dsecondnumber << " = " <<
  47. (dfirstnumber * dsecondnumber) << endl;
  48. break;
  49.  
  50. case '/':
  51. if (dsecondnumber == 0) {
  52. cout << " that is invalid " << endl;
  53. }else{
  54. cout << "the answer is: " << dfirstnumber << "/" << dsecondnumber << "=" <<
  55. (dfirstnumber / dsecondnumber) << endl;
  56. }
  57.  
  58. break;
  59. default
  60. cout << "that is an invalid operation" << endl;
  61. break;
  62. }
  63. cout << "would you like to start again? (y or n)" << endl;
  64. cin >> cDoagain;
  65.  
  66. }while (cDoagain == 'y' || cDoagain == 'Y');
  67.  
  68. system("PAUSE");
  69.  
  70. return 0;
  71. }
Last edited by stymiee; Oct 23rd, 2007 at 9:48 pm. Reason: added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DejanL23 is offline Offline
4 posts
since Oct 2007
Oct 23rd, 2007
0

Re: Check my code, There is 1 error, cant find it

I am very surprised that Visual Basic found only one error considering this code isn't written in Visual Basic ... it's written in C++.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002
Oct 23rd, 2007
0

Re: Check my code, There is 1 error, cant find it

line 60 - Error 1 error C2065: 'default' : undeclared identifier d:\COSC1436\temp\temp.cpp 60

and line 60 - Error 2 error C2146: syntax error : missing ';' before identifier 'cout' d:\COSC1436\temp\temp.cpp 60


this is what I found when trying to compile in C++

Greg
Reputation Points: 14
Solved Threads: 3
Junior Poster in Training
chizy2 is offline Offline
61 posts
since Apr 2005
Oct 23rd, 2007
0

Re: Check my code, There is 1 error, cant find it

You need to add a colon after your default statement on line 59.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
FerrousRex is offline Offline
17 posts
since Sep 2007
Oct 23rd, 2007
0

Re: Check my code, There is 1 error, cant find it

You need to describe the error. No one is going to spend an hour trying to find the error, then pour over your code to fix it. You need to describe the error and the circumstances with which it happens.
Moderator
Reputation Points: 3281
Solved Threads: 895
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Oct 24th, 2007
0

Re: Check my code, There is 1 error, cant find it

thanks guys.

sorry about the mistakes on the post and not descrbing the error, I was in a hurry before school, so I just did a quick post.

line 59 needed ";" after default
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DejanL23 is offline Offline
4 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: help plz
Next Thread in C++ Forum Timeline: Quick Question! Post/pre Inc!





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


Follow us on Twitter


© 2011 DaniWeb® LLC