I probably shouldn't do this but by posting this amateurish
code some of the beginners some of my fellow hobbyists who are also
trying to learn something might be encouraged or see something to
criticize or make the basis for discussion. There are possibly
bugs in it of which I'm still unaware as it's an ongoing sort of
first real project for me.
Kurt Kuzba was gracious enough to let me know about cprint
and get me out of a bog so I could continue and I thank him
enormously for that.
This is compiled with a Borland, version 3 compiler. Look
at it carefully because I have no idea about such things as
portability yet. I wrote it to interest the kids next door in
elementary math and in the computer which they generously take over
when they're here!!
Any and all comments truly welcome - no matter how harsh:
So here it is, for good or ill:
#include
#include
#include
#include
#include // for exit statement
#define YES 1
#define NO 0
int num1, num2, guess, ans, i, c, proceed=YES;
addCalc();
minusCalc();
multCalc();
divCalc();
int menu();
main()
{
menu();
return 0;
}
int menu()
{
c=30;
clrscr();
gotoxy(c,10);
textcolor(14);
cputs("Would you like to practice a little ");
c=35;
gotoxy(c,11);
textcolor(9);
cputs("1. Addition?");
gotoxy(c,12);
textcolor(10);
cputs("2. Subtraction?");
gotoxy(c,13);
textcolor(13);
cputs("3. Multiplicaton?");
gotoxy(c,14);
textcolor(11);
cputs("4.Division?");
gotoxy(c,15);
textcolor(11);
cputs("5. Quit?");
do
{
gotoxy(c,17);
textcolor(15);
cputs("Enter your choice: ");
scanf("%d", &i);
switch(i)
{
case 1: addCalc(); clrscr(); menu(); break;
case 2: minusCalc(); clrscr(); menu(); break;
case 3: multCalc(); clrscr(); menu(); break;
case 4: divCalc(); clrscr(); menu(); break;
case 5:
clrscr();
gotoxy(c,12);
textcolor(11);
cputs("Thanks for playing!");
exit(0);
} // end switch statement
}while (i 5);
return i;
}
addCalc()
{
clrscr();
c=20;
gotoxy(c, 10);
textcolor(2);
cputs("ADDITION PROBLEM:");
gotoxy(c, 12);
cputs("Type in the first number (Addend)? ");
cin >> num1;
gotoxy(c, 13);
cputs("Type in the second number (Addend)? ");
cin >> num2;
ans = num1 + num2;
gotoxy(c, 14);
cputs("What do you think is the answer (called the SUM)? ");
cin >> guess;
gotoxy(c, 15);
cprintf("The answer is ");
textcolor(14);
cprintf("%d", ans);
textcolor(2);
gotoxy(c, 16);
cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
cout << endl;
gotoxy(c, 18);
cprintf("Would you like to try another (Y/N)? ");
do {
guess = (0 == (guess = getch())) ? -getch() : guess;
guess = toupper(guess);
} while(guess != 'Y' && guess != 'N');
textcolor(9);
gotoxy(c,22);
cprintf("Press any key");
getch();
return 0;
}
minusCalc()
{
clrscr();
c=20;
gotoxy(c, 10);
textcolor(2);
cputs("SUBTRACTION PROBLEM:");
gotoxy(c, 12);
cputs("Type in the Minuend (number to subract FROM: ");
cin >> num1;
gotoxy(c, 13);
cputs("Now, type in the Subtrahend (number to subract: ");
cin >> num2;
ans = num1 - num2;
gotoxy(c, 14);
cputs("What do you think is the answer (REMAINDER)? ");
cin >> guess;
gotoxy(c, 15);
cprintf("The answer is ");
textcolor(14);
cprintf("%d", ans);
textcolor(2);
gotoxy(c, 16);
cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
cout << endl;
gotoxy(c, 18);
cprintf("Would you like to try another (Y/N)? ");
do {
guess = (0 == (guess = getch())) ? -getch() : guess;
guess = toupper(guess);
} while(guess != 'Y' && guess != 'N');
textcolor(9);
gotoxy(c,22);
cprintf("Press any key");
getch();
return 0;
}
multCalc()
{
clrscr();
c=20;
gotoxy(c, 10);
textcolor(2);
cputs("MULTIPLICATION PROBLEM:");
gotoxy(c, 12);
cputs("Type in the number to be multiplied (MULTIPLICAND): ");
cin >> num1;
gotoxy(c, 13);
cputs("Type in the number to multiply it by (MULTIPLIER): ");
cin >> num2;
ans = num1 * num2;
gotoxy(c, 14);
cputs("What do you think is the answer (PRODUCT)? ");
cin >> guess;
gotoxy(c, 15);
cprintf("The answer is ");
textcolor(14);
cprintf("%d", ans);
textcolor(2);
gotoxy(c, 16);
cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
cout << endl;
gotoxy(c, 18);
cprintf("Would you like to try another (Y/N)? ");
do {
guess = (0 == (guess = getch())) ? -getch() : guess;
guess = toupper(guess);
} while(guess != 'Y' && guess != 'N');
textcolor(9);
gotoxy(c,22);
cprintf("Press any key");
getch();
return 0;
}
divCalc()
{
clrscr();
c=20;
gotoxy(c, 10);
textcolor(2);
cputs("DIVISION PROBLEM:");
gotoxy(c, 12);
cputs("Type in the number to be divided (DIVIDEND): ");
cin >> num1;
gotoxy(c, 13);
cputs("Type in the number to divide it by (DIVISOR): ");
cin >> num2;
ans = num1 / num2;
gotoxy(c, 14);
cputs("What do you think is the answer (QUOTIENT): ");
cin >> guess;
gotoxy(c, 15);
cprintf("The answer is ");
textcolor(14);
cprintf("%d", ans);
textcolor(2);
gotoxy(c, 16);
cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
cout << endl;
gotoxy(c, 18);
cprintf("Would you like to try another (Y/N)? ");
do {
guess = (0 == (guess = getch())) ? -getch() : guess;
guess = toupper(guess);
} while(guess != 'Y' && guess != 'N');
textcolor(9);
gotoxy(c,22);
cprintf("Press any key");
getch();
return 0;
}
------------------------------------END HERE------------------------
Again, thanks, Kurt for your generous help and code examples.
Sincerely,
Frank
--- PPoint 2.03
---------------
* Origin: Maybe in 5,000 years - frankmas@juno.com (1:396/45.12)
|