TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK MASINGILL
from: JERRY COFFIN
date: 1997-08-23 09:31:00
subject: MATHPLAY.CPP 09:31:5508/23/97

On (22 Aug 97) Frank Masingill wrote to All...
 FM>    do
 FM>    {
 FM>         gotoxy(c,17);
 FM>         textcolor(15);
 FM>         cputs("Enter your choice: ");
 FM>         scanf("%d", &i);
 FM>         switch(i)
 FM>     {
 FM>              case 1: addCalc();  clrscr(); menu(); break;
 FM>              case 2: minusCalc(); clrscr(); menu();  break;
 FM>              case 3: multCalc(); clrscr(); menu(); break;
 FM>              case 4: divCalc(); clrscr(); menu();  break;
 FM>              case 5:
 FM>                  clrscr();
 FM>                  gotoxy(c,12);
 FM>                  textcolor(11);
 FM>            cputs("Thanks for playing!");
 FM>                  exit(0);
 FM>         }                  // end switch statement
 FM>    }while (i  5);
 FM>    return i;
 FM> }
Okay, here we've got a more serious problem: we're calling menu() again
every time we do something.  What we need is to repeat the menu without
calling it again, something like this:
    do {
        gotoxy(c, 17);
        textcolor(15);
        cputs("Enter your choice: ");
        scanf("%d", &i);
        switch (i) {
            case 1: addCalc();      break;
            case 2: minusCalc();    break;
            case 3: multCalc();     break;
            case 4: divCalc();      break;
            case 5:
                clrscr();
                gotoxy(c, 12);
                textcolor(11);
                cputs("Thanks for playing!");
                break;
        }
    while ( i != 5 );
this repeatedly waits for you to enter a key until you push '5'.
However, you can make it a bit nicer for the user by using getch()
instead of scanf() to read the character.  This way, they only have to
push one digit, and not the enter key:
    do {
        // ...
        cputs("Enter your choice: ");
        ch = getch();
        switch(ch) {
            case '1': addCalc();    break;
            case '2': minusCalc();  break;
            // ...
        }
        // ...
    } while (ch != '5');
That's all I'm going to go into for now.  There's a lot more along this
line that _could_ be gone into, but I'll let you work at figuring this
out before I try to go into anything more complex.
    Later,
    Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.