arithmetic calculator

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 16
Reputation: jjf3rd77 is an unknown quantity at this point 
Solved Threads: 0
jjf3rd77's Avatar
jjf3rd77 jjf3rd77 is offline Offline
Newbie Poster

arithmetic calculator

 
0
  #1
31 Days Ago
I keep getting errors in my code. I can enter the first number 1 fine but then is says that letter c or a is not initialized. What am I doing wrong? This is what i have so far

  1. // Exercise 8.13: ComparingRates.cpp
  2. // Application that calculates the amount of money the user will have
  3. // after 10 years at several interest rates.
  4.  
  5.  
  6. #include <string>
  7. #include <iostream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. void main ( )
  12. {
  13. int choice;
  14. double a, b, c;
  15. char an;
  16. cout << "Please enter the operation you want" << endl;
  17. cout << "Press 1 for addition" << endl << "Press 2 for subtraction" <<
  18. endl << "Press 3 for division" << endl << "Press 4 for multiplication"
  19. << endl;
  20. cin >> choice;
  21. cout << "Please enter the numbers you want to do calculation with" << endl;
  22. while (an = 'y')
  23. {
  24. if (choice == 1)
  25. {
  26. c = a + b ;
  27. }
  28. if (choice == 2)
  29. {
  30. c = a - b;
  31. }
  32. if (choice == 3)
  33. {
  34. c = a / b;
  35. }
  36. if (choice == 4)
  37. {
  38. c = a * b;
  39. }
  40. cout << "Here is your result: " << c << endl;
  41. cout << "want to do it again?" << endl;
  42. cin >> an;
  43. }
  44. }
  45.  
  46. /**************************************************************************
  47.   * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
  48.   * Pearson Education, Inc. All Rights Reserved. *
  49.   * DISCLAIMER: The authors and publisher of this book have used their *
  50.   * best efforts in preparing the book. These efforts include the *
  51.   * development, research, and testing of the theories and programs *
  52.   * to determine their effectiveness. The authors and publisher make *
  53.   * no warranty of any kind, expressed or implied, with regard to these *
  54.   * programs or to the documentation contained in these books. The authors *
  55.   * and publisher shall not be liable in any event for incidental or *
  56.   * consequential damages in connection with, or arising out of, the *
  57.   * furnishing, performance, or use of these programs. *
  58.   **************************************************************************/
Knowledge is earned, Education is learned.- me
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,346
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 169
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso
 
0
  #2
31 Days Ago
Tell me if you see a problem here :
char an;
cout << "Please enter the operation you want" << endl;
cout << "Press 1 for addition" << endl << "Press 2 for subtraction" <<
endl << "Press 3 for division" << endl << "Press 4 for multiplication"
<< endl;
cin >> choice;
cout << "Please enter the numbers you want to do calculation with" << endl;
while (an = 'y')

Then you say :
  1. cout << "Please enter the numbers you want to do calculation with" << endl;

In which you don't do this :
  1. cin >> a >> b;
1) What word becomes shorter if you add a letter to it? 
      [ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
      [*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC