I am working on some homework right now and the program has to return two specified values depending on the key value the user enters. I only had to write the bottom portion of the program as the top portion was given to me as a shell.
It runs but is not returning the correct values, can anyone give me any insight as to why it is not returning the correct vaues? I am not sure if I am understanding completely how structs pass values and such...
Thanks
#include <iostream.h>
// Definition of the PhoneTones struct
struct PhoneTones
{
int rowTone, // Frequencies of the tones generated by a key press
colTone;
};
// Function prototype
PhoneTones keyToTones ( char key );
//--------------------------------------------------------------------
int main()
{
char inputKey; // Input key
PhoneTones keyFreqs; // Frequencies of the corresponding tones
// Read in a series of keys and output the corresponding tones.
cout << endl << "Enter key pressed (0-9, *, or #): ";
cin >> inputKey;
keyFreqs = keyToTones(inputKey);
cout << "Tones produced at " << keyFreqs.rowTone << " and "
<< keyFreqs.colTone << " Hz" << endl;
system("pause");
return 0;
}
//--------------------------------------------------------------------
// Insert your keyToTones function here.
//--------------------------------------------------------------------
PhoneTones keyToTones ( char key )
{
PhoneTones Freqs;
switch (key)
{
case '1': case '2': case '3': Freqs.rowTone = 697; break;
case '4': case '5': case '6': Freqs.rowTone = 770; break;
case '7': case '8': case '9': Freqs.rowTone = 852; break;
case '*': case '0': case '#': Freqs.rowTone = 941; break;
}
switch (key)
{
case '1': case '4': case '7': case '*': Freqs.colTone = 1209; break;
case '2': case '5': case '8': case '0': Freqs.colTone = 1336; break;
case '3': case '6': case '9': case '#': Freqs.colTone = 1477; break;
}
}