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

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2007
Posts: 4
Reputation: DejanL23 is an unknown quantity at this point 
Solved Threads: 0
DejanL23 DejanL23 is offline Offline
Newbie Poster

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

 
0
  #1
Oct 23rd, 2007
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,043
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 130
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

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

 
0
  #2
Oct 23rd, 2007
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++.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 61
Reputation: chizy2 is an unknown quantity at this point 
Solved Threads: 3
chizy2's Avatar
chizy2 chizy2 is offline Offline
Junior Poster in Training

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

 
0
  #3
Oct 23rd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 13
Reputation: FerrousRex is an unknown quantity at this point 
Solved Threads: 2
FerrousRex's Avatar
FerrousRex FerrousRex is offline Offline
Newbie Poster

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

 
0
  #4
Oct 23rd, 2007
You need to add a colon after your default statement on line 59.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

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

 
0
  #5
Oct 23rd, 2007
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 4
Reputation: DejanL23 is an unknown quantity at this point 
Solved Threads: 0
DejanL23 DejanL23 is offline Offline
Newbie Poster

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

 
0
  #6
Oct 24th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC