rtumatt
October 5th, 2009, 07:55 PM
This code is in no way finished but what the eventual aim of the program is to record lower case key strokes then display them when the program terminates as displayed in case a and b (other letters i have not yet implemented). The code runs fine and does what i want however when the loop runs it asks twice for an input but takes the first as blank and the second letter you enter a letter. Why is this?
#include <iostream>
using namespace std;
int main()
{
char letter;
int num = 0;
string textSaved;
while (letter !='0'){
cout << "enter any character : ";
cin.get(letter);
switch (letter) {
case 'a': //cout << "thats an a";
num ++;
textSaved = textSaved + 'a';
break;
case 'b': //cout << "\nthats a b";
num ++;
textSaved = textSaved + 'b';
break;
case 'c': cout << "thats a c";
break;
case 'd': cout << "\nthats a d";
break;
case 'e': cout << "\nthats a e";
break;
case 'f': cout << "\nthats a f";
break;
case 'g': cout << "\nthats a e";
break;
default: cout << "\nthats not A B or C";
}
// cout; "\n";
}
cout << "\n\n\n" << "Letters pressed : " <<textSaved << "\n\n\n";
cout <<"number of letters: " << num << "\n\n";
}
#include <iostream>
using namespace std;
int main()
{
char letter;
int num = 0;
string textSaved;
while (letter !='0'){
cout << "enter any character : ";
cin.get(letter);
switch (letter) {
case 'a': //cout << "thats an a";
num ++;
textSaved = textSaved + 'a';
break;
case 'b': //cout << "\nthats a b";
num ++;
textSaved = textSaved + 'b';
break;
case 'c': cout << "thats a c";
break;
case 'd': cout << "\nthats a d";
break;
case 'e': cout << "\nthats a e";
break;
case 'f': cout << "\nthats a f";
break;
case 'g': cout << "\nthats a e";
break;
default: cout << "\nthats not A B or C";
}
// cout; "\n";
}
cout << "\n\n\n" << "Letters pressed : " <<textSaved << "\n\n\n";
cout <<"number of letters: " << num << "\n\n";
}