The program was successfully compiled using Borland 5.02.
The program controls the input type by user using ASCII codes. The input mode is similar to QuickBasic's INKEY.
The program is working and tested okay. Much effort had been put in, but the problem is that the subroutines for handling string is not working yet. Also string to numeric conversion is not working. They have been remarked out.
Need some expert tips to enable subroutines and string to numeric variable conversion to work.
regards,
YongBM
#include <stdio.h>
#include <stdlib>
#include <string>
#include <math>
using namespace std;
// string spaz(int,string);
//string datainp(string,int);
void msg() {cout << "\nPress Esc to Exit, Any other key to continue."; }
void presskey()
{
cout << "\n\nAny other key to continue.";
cin.ignore();
// cin.get();
// system("CLS");
}
void msg2()
{
cout << "\n// INPUT TYPE CONTROL";
cout << "\n// ------------------";
cout << "\n// Weight Condition 3 Numbers and decimals only ";
cout << "\n\n";
}
char *endptr;
double weight;
int xc=0;
int condi;
string xcon;
int getche(void);
int main(void)
{
string xconcate;
string efield="";
// Weight Condition 3 Numbers and decimals only
string sweight="";
efield="Weight";
condi=3;
// sweight=datainp(efield,condi);
// cout << "Validated Numbers and decimal, Weight: " << sweight << endl;
// return 0;
// }
//
//
//
// Data Entry subroutine
//string datainp(string &efield,int &condi)
// {
int xcond=condi;
int c;
int extended = 0;
// char xcon, *endpter;
redo:
std::string concate = "";
msg2();
msg();
condi=xcond;
cout << "\nCondition :" << condi << endl;
cout << "\n\n Enter "<< efield << ": ";
do
{
c = getche();
if (c==27) { break; }
char inp=c; // assign char from ASCII code Backspace's ASCII code is 8
if (!c)
extended = getche();
if (extended)
{
//
}
else if (condi==3) // Only Numbers and decimal allowed
{
if ((c >=48 && c <=57) || (c>=46 && c<=46))
{
concate += inp; // string concatenation.. The character isn't extended
}
else
{
// SUBROUTINE for handling backspacing NOT WORKING!!
// spaz(c,concate);
if (c !=8) // not backspace
{
cout << "\x08";
}
else
{
int len = concate.length();
if (len >0)
{
cout << " ";
cout << "\x08";
concate=concate.substr(0,len-1);
}
else
{
cout << " ";
}
}
}
}
} while (c != 13); // ascii 13 is <enter> or <carriage return>
int len = concate.length();
cout << "\n String length =" << len << " chars" << endl;
if (condi==3) // Coversion from string to numeric.
{
xcon=concate;
cout << "\n Weight entered as string = " << xcon;
// convert string to numeric variable
// weight = strtod(xcon,&endptr);
cout <<"\n\n strtod(xcon,&endptr) Conversion from string to number is not working.. \n Test weight is numeric, weight*10 = " << weight*10 << " " << endl;
}
//
msg();
c = getche();
if (c != 27) {system("CLS"); goto redo;}
// return concate;
} // main terminate
/* SUBROUTINE TO MOVE CURSOR POSITION
string=spaz(int xc,string& xconcate)
{
if (xc !=8) // not backspace
{
cout << "\x08";
}
else
{
int len = xconcate.length();
if (len >0)
{
cout << " ";
cout << "\x08";
xconcate=xconcate.substr(0,len-1);
}
else
{
cout << " ";
}
}
return xconcate;
} //
*/