Slimelite BBS

Thanks...

Back to EMULATE

From Tom Chantry · 1996-04-06 01:15 · #73543 in EMULATE

Hi Greg!

Sunday, 31 March 1996 14:18:51, Greg Aluise was charged with being 'Drunk in
Charge Of A
 Modem, his one phone call to All went like this:

 GA>
 GA> #include <conio.h>
 GA> #include <iostream.h>
 GA>
 GA> void main(void)
 GA>   {
 GA>    int var1;
 GA>    int var2;
 GA>    char buffer[80];
 GA>    char *string
 GA>
 GA>    cout <<"Enter a number:";
 GA>    buffer[0]=3;
 GA>    string = cgets(buffer);

 GA>    v1 = int(string);

   look at the fubctions ecvt () and fcvt () to convert strings to
   numbers, or try
    v1 = (int) *string, but this will only give you the ascii value of
    the number enterd..
    heres my code :
     void main ()
      {
      int var1=0, var2=0, total=0;
      cout << endl << "Enter Number 1";
      var1 = getche();
      var1 -= 48 // converts ascii code to integrar
      cout << "\n And Number 2";
      var2 = getche();
      var2-=48;
      total = var1+var2;
      cout << total;
      }


 GA>    cout <<"\n\rEnter a second number to add to first:";
 GA>    buffer[0]=3;
 GA>    string = cgets(buffer);
 GA>    v2 = int(string);
 GA>    cout <<"\n\rThe result is: " << (v1 + v2);
 GA>  }
 GA>


 GA>         When I compile this code, it compiles fine with no warning
 GA> or errors, but when I run the exe and enter like 1 & 2, it comes up with
 GA> 65344,
 GA> now the only reason I am using cgets instead of cin, is because I want
 GA> the
 GA> program to input info in different colors in text mode, if somebody knows
 GA> how
 GA> to make this work, or to make cin work in different colors I would
 GA> GREATLY!!
  You could try using 'cprintf' and 'cscanf', which work well with
  colors..  Or you could use   getch () to input each character and then
  output it with something else..


______
 |         * PGP Public Key Available, FREQ TOMPGP from 2:440/7
 |         * Internet: tomc@spuddy.mew.co.uk
 | O M

.!. Tap with hammer here >████< for "breaking glass" sound effect

--- Terminate 3.10b09/Pro*bt
 * Origin: Come To The 'Allsports' Echo... Mail me for details.. (2:440/7.23)