I am making a program where the user has to input text, and the program outputs the appropriate string.
I made this program using if else statement, but professor said not to use if and else.
So I want to know if I can use the switch statement.
I know that switch statement work for char and int only. (As from what I read from the book).
So far I got this:
#include <iostream>
#include <string>
using namespace std;
int main (void)
{
char word;
cout<< "Enter word to define: \n";
word = getchar();
switch (word){
case 'd':
cout<< "A four legged animal";
break;
case 'c':
cout<< "A animal scared of water";
break;
default:
cout<< "not in dictionary";
}
return 0;
}
It was actually
case 'dog'
case 'c' etc...but when i type a word it shows the default.
It works for the first character, which is of no use since there may be other words starting with the same character.
This program is a dictionary program, I have recieved helped about a few weeks back with it using if else, but like i mentioned professor did not want it that way...if the switch statement does not result, I might have to use structures as that is what th professor used in his code in which I took a glimpse at.