Hi everyone. I'm basically making a "logger" program that takes data input by the user and creates a log of it. The program displays a menu to the user like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void menu()
{
int decision=0;
cout << "Menu: " << endl;
cout << "\tOption 1: View your data log" << endl;
cout << "\tOption 2: Append your data log" << endl;
cout << "\tOption 3: Quit the program" << endl;
cout << "Option: ";
cin >> decision;
if (decision == 1)
fileReader();
else if (decision == 2)
eventLogger();
else
quit(); //thank user for using program, exit;
}//menu
|
That part works. Let's say the user inputs 2 so we jump to eventLogger(). The program is for a game, so it asks the user if they want to count kills. This is where it doesn't work.
I'm not sure how to correctly read/identify characters. I want the program to be able to recognize if a character isn't Y for yes and isn't N for no. It should also be able to recognize if it is Y and if it is N.
Finally, I'd also like to be able to use a while loop for while a character isn't Q, so the user has an easy way to break the loop and get back to a menu without being prompted every time.
Here's my code for eventLogger():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
void eventLogger()
{
char value[800];
char killCount;
char choice[10];
char drops[600];
char monster[200];
char item[200];
int kill=0;
time_t rawtime;
struct tm * timeinfo;
char timeData[100];
output.open("log.txt");
cout << "Enter Q at any time to return to menu." << endl;
cout << "You may enter any data in any format you wish. Date/Time is automatic." << endl;
cout << endl;
cout << "Would you like the program to count kills? (Y/N): ";
cin >> killCount;
if (killCount != 'Y' && killCount != 'N')
{
cout << "Invalid choice." << endl;
eventLogger();
}//if invalid*/
else if (killCount == 'Y')
{
kill=0;
while (monster != 'Q' && drops != 'Q')
{
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (timeData,100,"%I:%M:%S%p",timeinfo);
output << " " << timeData;
cout << "Monster Name: ";
cin >> monster;
output << " " << monster;
kill++;
output << " Kill #" << kill;
cout << "Drops: ";
cin >> drops;
output << " " << drops;
cout << "\tData has been logged." << endl;
}//while
}//else if killCount = yes
else if (killCount == 'N')
{
cout << "Are you logging Monster drops or Regular items? (Monster/Regular): ";
cin >> choice;
if (choice == 'Monster')
{
cout << "Monster Name: ";
cin >> monster;
output << monster;
while (drops != 'Q')
{
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (timeData,100,"%I:%M:%S%p",timeinfo);
output << " " << timeData;
cout << "Drops: ";
cin >> drops;
output << " " << drops;
cout << "Data has been logged." << endl;
}//while
}//if monster
else if (choice == 'Regular')
{
while (value != 'Q')
{
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (timeData,100,"%I:%M:%S%p",timeinfo);
output << " " << timeData;
cout << "Item Name: ";
cin >> item;
output << " Item:" << item;
cout << "Value: ";
cin >> value;
output << " Value: " << value;
cout << "Data has been logged." << endl;
}//while
}//else if regular
}//else if kill count = no
/*else
{
cout << "Invalid choice." << endl;
eventLogger();
}*/
cout << "Data log complete. Returning to menu." << endl;
separator();
menu();
}//eventLogger
|
These are the types of errors I get:
1>c:\users\kingtrunks\documents\runescape\runescapelogger\runescapelogger.cpp(127) : error C2446: '!=' : no conversion from 'int' to 'char *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\kingtrunks\documents\runescape\runescapelogger\runescapelogger.cpp(127) : error C2040: '!=' : 'char [200]' differs in levels of indirection from 'int'
1>c:\users\kingtrunks\documents\runescape\runescapelogger\runescapelogger.cpp(127) : error C2446: '!=' : no conversion from 'int' to 'char *'
|
I've looked up string comparisons, how to identify letters in Strings, and how to use while loops with chars, but haven't been able to find anything to fix my problem. I usually code in Java, so I'm having a little trouble with C++ it seems as far as chars/Strings go.
Any help would be appreciated. I guess I mostly just need to know how to go about finding out if the char is Q, is not Q, etc.
Thanks,
-KT