#include <iostream>
usingnamespace std;
int main()
{
int cat=0;
if (cat=1)
{
string word;
cout<<"Please enter a word: ";
cin>> word;
cin.ignore();
cout<<"You entered the word: "<< word <<"\n";
cin.get();
}
else
{
int num;
cout<<"Please enter a number: ";
cin>> num;
cin.ignore();
cout<<"You entered the number "<< num <<"\n";
cin.get();
}
}
#include <iostream>
usingnamespace std;
int main()
{
int cat;
cout<<"word or number?";
if cin>>"word";
{
(cat=1)
}
if cin>>"number";
{
(cat=2)
}
else
{
cout>>"write word or number";
}
if (cat=1)
{
string word1;
cout<<"Please enter a word: ";
cin>> word1;
cin.ignore();
cout<<"You entered the word: "<< word1 <<"\n";
cin.get();
}
else
{
int num;
cout<<"Please enter a number: ";
cin>> num;
cin.ignore();
cout<<"You entered the number "<< num <<"\n";
cin.get();
}
}
Lines 8 and 12: You can't read from the input stream 'cin' into a constant character array. You could read into a string variable instead:
You need a loop (like a do-while loop) so that the first input process can repeat if the user doesn't enter 'word' or 'number'.
Lines 8 and 12: 'if' control structures need a condition that can evaluate as true/false inside round brackets (...). No semicolon at the end of this line...
Lines 10 and 14: Don't forget the semicolon at the end of the line.
Line 18: Should be cout << ...
Line 21: You have an assignment operator, you should be using the comparison operator ==.
Line 1: Don't forget to #include <string>
That's a lot to take in. Here's a fixed version, but I suggest you don't look at it until you have a go yourself...