Please support our C++ advertiser: Programming Forums
Views: 445 | Replies: 1
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()
function
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
c++ Syntax (Toggle Plain Text)
void getFract(char op, int fractNo, int & num, int & den) { cout << " Enter the numerator: "; cin >> num; if ( op == '/' && fractNo == 2 && num == 0 ) { cout << "\nTo divide, the second fraction must be nonzero\n"; while ( num == 0 ) { cout << "\nEnter a nonzero number for the numerator: "; cin >> num; } // endwhile } // endif cout << " Enter the denominator: "; cin >> den; if ( den = 0 ) { cout << "The denominator must be nonzero\n"; while ( den = 0 ) { cout << "\nEnter the denominator: "; cin >> den; } // endwhile } // endif }
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
-Edsger Dijkstra
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)







Threaded Mode