July 23rd, 1999, 09:37 PM
How do I take in a input word but only look at the first character?
cin >> Minus
(but only look at the M)
cin >> Minus
(but only look at the M)
|
Click to See Complete Forum and Search --> : input sngl char July 23rd, 1999, 09:37 PM How do I take in a input word but only look at the first character? cin >> Minus (but only look at the M) Paul Belikian July 23rd, 1999, 10:37 PM Hi, is this what you are asking? char cFirstChar; char Minus[20]; cin >> Minus; cFirstChar = Minus[0]; Regards, Paul Belikian July 23rd, 1999, 10:44 PM int main() { char command_character; double r1; double r2; double acc; cout.setf(ios::fixed, ios::floatfield); //Set up floating pt. cout.setf(ios::showpoint); // output format cout << setprecision(1); DisplayMenu();//has a cout stating to type in char but if more than one letter is typed in it goes crazy. cin >> command_character; while ((command_character != 'Q') && (command_character != 'q')) { switch(command_character) { case '+': case 'a': case 'A': Addition(r1,r2, acc); break; Paul Belikian July 23rd, 1999, 11:05 PM I think you need to make sure command_character is big enough to hold as many chars that could be typed in. Right now char command_character is only 1 char long. You need to make an array and pass only the first char... #define MAX_INPUT_SIZE 100 int main() { char command_character[MAX_INPUT_SIZE]; double r1; double r2; double acc; cout.setf(ios::fixed, ios::floatfield); //Set up floating pt. cout.setf(ios::showpoint); // output format cout << setprecision(1); DisplayMenu();//has a cout stating to type in char but if more than one letter is typed in it goes crazy. cin >> command_character; while ((command_character[0] != 'Q') && (command_character[0] != 'q')) { switch(command_character[0]) { case '+': case 'a': case 'A': Addition(r1,r2, acc); break; Regards, Paul Belikian July 24th, 1999, 06:32 AM Thanks,Paul my program is now finished, up and running thanks to you!!! Duane codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |