Yes yes, I know you haven't heard from me in a while. Holidays are brilliant hey! Hope everyone enjoyed theirs!
Anyhow, I've just written this little program. I'll be adding more things to it during the course of tomorrow, but for now I was wondering if there are any comments or crits that people could give me on the code in it's current stage.
Much appreciated as alwaysCode:/* ############################################## ## Addition & Subtraction Assistance Program ############################################## ## ## Written by : CC ## Last modified : 15/01/2004 ## Comments : A program designed to help children practise simple addition ## and subtraction sums. ############################################## */ #include <cstdlib> using std::rand; using std::srand; #include <iomanip> using std::setw; #include <iostream> using std::cout; using std::cin; using std::setw; // Prototypes char addition(); char subtraction(); char repeat( int total1, int total2 ); inline void screen_clear(); int main() { int pickAddSub; char again; again = 'y'; cout << "Addition & Subtraction Assistance Program" << '\n'; srand( time( 0 ) ); while ( again == 'y' ) { // Giving pickAddSub a random value of either 1 or 2 pickAddSub = ( 1 + rand() % 2 ); if ( pickAddSub == 1 ) again = addition(); else if ( pickAddSub == 2 ) again = subtraction(); screen_clear(); } return 0; } char addition() { int number1, number2, usertotal, total; char again; srand( time( 0 ) ); number1 = ( 0 + rand() % 15 ); number2 = ( 0 + rand() % 15 ); total = number1 + number2; cout << "\nHere is the sum...\n" << setw( 6 ) << number1 << " + " << number2 << " = "; cin >> usertotal; again = repeat( usertotal, total ); return again; } char subtraction() { int number1, number2, usertotal, total; char again; srand( time( 0 ) ); number1 = ( 0 + rand() % 15 ); number2 = ( 0 + rand() % 15 ); // We cannot have negative numbers if ( number1 > number2 ) { total = number1 - number2; cout << "\nHere is the sum...\n" << setw( 6 ) << number1 << " - " << number2 << " = "; cin >> usertotal; } else { total = number2 - number1; cout << "\nHere is the sum...\n" << setw( 6 ) << number2 << " - " << number1 << " = "; cin >> usertotal; } again = repeat( usertotal, total ); return again; } char repeat( int total1, int total2 ) { char again; if ( total1 == total2 ) { cout << "Very Good!\n" << "Would you like to try again? [y/n] "; cin >> again; return again; } else { cout << "No.\n" << "Would you like to try again? [y/n] "; cin >> again; return again; } } inline void screen_clear() { system ( "CLS" ); }![]()



LinkBack URL
About LinkBacks




CornedBee