#include <iostream> // cout
#include <conio.h> // getch
#include <string>
#include <cmath>
using namespace std;
// Globals
#define MAX_STRING 50
//Function Prototype
int numberString();
// funtion prototypes
int numberString (int x);
int main () {
//locals
char firstName[MAX_STRING]; // string first-namespace
char key; // single-key entry
int i; //counter
cout << "Please type your first name: ";
i = 0;
do{
key = getch(); // take the character, but do not print to console
cout << flush; //clear input stream buffer
if (key == char(224) || key == char(96)) { // ignores 1rst byte of special 2 byte special keys
key = getch(); // get second byte
cout << flush;
}
if (key == char (13)) // if enter key
break; // jump out of loop
if (key == char(8) && i > 0) {
cout << "\b \b";
i--;
}
if ((key >= 65 && key <= 90) || (key >= 97 && key <= 122)) { // if key is upper or lower alpha-char
if (i== 0) { //if 1rst character in string
key = toupper(key); // then make uppercase
}
cout << key; //echo print character back to console screen
firstName[i] = key; // append to string
i++; // increment to next character in string
}
} while (i < 49);
firstName[i] = NULL;
cout << endl << "\nFirst Name: " << firstName << endl;
}
int numberString(){
//LOCALS
int number[30];
char key;
int count;
do {
key = getche();
cout << flush;
if (key == char(224) || key == char(96)) {
key = getch();
cout << flush;
}
if (key == char(13))
break;
if (key == char(8) && count > 0) {
cout << "\b \b";
count--;
}
if (key > 48 && key < 57)
cout << key;
number[count] = key;
count++;
} while (count < 49 );
number[count] = NULL;
cout << endl << "\nNumber: " << count << endl;
return 0;
} // function main
Would really appreciate the help..I know I probably messed the whole code up..
thank you
msqueen008
This post has been edited by no2pencil: 15 November 2010 - 08:56 PM
Reason for edit:: Added code tags

New Topic/Question
Reply




MultiQuote





|