User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,816 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,575 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 405 | Replies: 1
Reply
Join Date: Jun 2006
Location: USA
Posts: 1,025
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 10: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  
Join Date: Sep 2004
Posts: 6,050
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 416
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Needing some help

  #2  
May 2nd, 2007
>if ( den = 0 ) {
>while ( den = 0 ) {
= is assignment, == is comparison.
Member of: Beautiful Code Club.
Reply With Quote  
Reply

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)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC