Is there any specific reason not use std::string
?
A solution, using std::string
would be:
#include<iostream>
using namespace std;
void setKey(string& keyPress);
int main()
{
string keyPress;
setKey(keyPress);
//rest here
}
void setKey(string& keyPress)
{
cout << "Enter the day using the number keypad: "<< endl << endl;
cin >> keyPress;
cout << endl << endl;
if (keyPress == "666329")
cout << "Monday" << endl << endl;
else if (keyPress == "8837329")
cout << "Tuesday" << endl << endl;
}
If you still want to use c-style
strings, you need to compare them with the following function:
strcmp
Moreover, you have a memory leak in your code. You are using new
without delete
.
solved using char for dynamic allocation