RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 445 | Replies: 1
Join Date: Jun 2006
Location: USA
Posts: 1,082
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Rep Power: 7
Solved Threads: 4
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Help Needing some help

  #1  
May 2nd, 2007
Hey guys, this is a calculator program.
I keep getting 0s for my answers... is there something wrong with the logic in this function:

main()
cin >> choice;
    while ( choice != 'q' && choice != 'Q' ) {        
        cout << "For first fraction\n";
        getFract(choice, 1, num1, den1);
        cout << "For second fraction\n";
        getFract(choice, 2, num2, den2);

function
  1. void getFract(char op, int fractNo, int & num, int & den)
  2. {
  3. cout << " Enter the numerator: ";
  4. cin >> num;
  5. if ( op == '/' && fractNo == 2 && num == 0 ) {
  6. cout << "\nTo divide, the second fraction must be nonzero\n";
  7. while ( num == 0 ) {
  8. cout << "\nEnter a nonzero number for the numerator: ";
  9. cin >> num;
  10. } // endwhile
  11. } // endif
  12.  
  13. cout << " Enter the denominator: ";
  14. cin >> den;
  15. if ( den = 0 ) {
  16. cout << "The denominator must be nonzero\n";
  17. while ( den = 0 ) {
  18. cout << "\nEnter the denominator: ";
  19. cin >> den;
  20. } // endwhile
  21. } // endif
  22. }
Last edited by Duki : May 2nd, 2007 at 11:32 am.
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:19 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC