| | |
please help
![]() |
•
•
Join Date: Aug 2007
Posts: 4
Reputation:
Solved Threads: 0
i know this is 2 easy for you guys, but please help..... Its been only 2 wks since i enrolled this class and they gave me this assignment.... please check if its correct. thank you so much
cpp Syntax (Toggle Plain Text)
#include<iostream> using namespace std; char vowels[]={a,e,i,o,u}; char n; char main() { cout<<“Please Enter a Character:\n”; cin>>n; { if (n=vowels) cout<<“n is a VOWEL\n”; else cout<<“n is CONSONANT\n”; } return 0; }
Last edited by WolfPack; Aug 29th, 2007 at 12:13 pm. Reason: ADDED [CODE=CPP][/CODE] TAGS
I am a begginer also but I believe you need main to be declared as The line isn't needed.
I would put inside int main().
For your branching statement you would declare each of the vowels in the condition statement i.e.
It would probably be a lot easier to use a switch statement though. i.e.
Only problem with this is that if someone enters something that is not an alphabet it will be considered a consonant.
C++ Syntax (Toggle Plain Text)
int main()
C++ Syntax (Toggle Plain Text)
char vowels[]={a,e,i,o,u};
I would put
C++ Syntax (Toggle Plain Text)
char n;
For your branching statement you would declare each of the vowels in the condition statement i.e.
C++ Syntax (Toggle Plain Text)
if (n == 'A' || n== 'a' || n == 'E' || ect...)
C++ Syntax (Toggle Plain Text)
switch (n) { case 'A': case 'a': case 'E': case 'e': case 'I': case 'i': case 'O': case 'o': case 'U': case 'u': { cout << "This letter is a Vowel." << endl; break; } default: { cout << "This letter is a consonant." << endl; } }
Last edited by Boldgamer; Aug 29th, 2007 at 12:33 pm.
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
Welcome to Daniweb. I see that Wolfpack helped formating your code since it was your first post. In the future please use code tags when posting information, like code, where you want to preserve indentation.
As another alternative you could use the array and a loop to read through array to check if the given char is a vowel or not. Of course this assumes you know about accessing elements of an array and control loops, etc.
Note how Boldgamer refers to single chars using single quotes before and after the char, and how Bolgamer used the == operator rather than the = operator for equals.
Trying to avoid global variables is considered good form in standard C++.
As another alternative you could use the array and a loop to read through array to check if the given char is a vowel or not. Of course this assumes you know about accessing elements of an array and control loops, etc.
Note how Boldgamer refers to single chars using single quotes before and after the char, and how Bolgamer used the == operator rather than the = operator for equals.
Trying to avoid global variables is considered good form in standard C++.
Last edited by Lerner; Aug 29th, 2007 at 12:41 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: school's back, and so am i :D
- Next Thread: Lexer- Tokenizer problem
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes classified code coding compatible compile console conversion count date delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file filewrite forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolutions iamthwee icon if...else ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node object output play pointer problem program programming project python random read recursion reference rpg string strings struct symbol temperature template test text text-file toolkit tree url values variable vector video win32 windows winsock wordfrequency wxwidgets






