GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-May-2008, 18:15
lilballeer lilballeer is offline
New Member
 
Join Date: May 2008
Posts: 16
lilballeer is on a distinguished road

Function program: getting "error C2064:"


Hello,
I keep getting this error for this program which is simply suppose to tell me if a letter is a vowel or not. error C2064: term does not evaluate to a function taking 1 arguments
Here is the code:

CPP / C++ / C Code:
#include <iostream>
 
using namespace std;
char isVowel (char letter);
int main()
{
 
 
    //Michael Casey; 5/7/08
 
    char letter; 
    char letterval;
    char isVowel;
 
 
cout << "Enter a letter: " << endl; 
    cin >> letter;
 
 
 
 
letterval = isVowel (letter); 
 
if (letterval == 1)
    cout << " the letter is a vowel "; 
else 
cout << "The letter is not a vowel"; 
 
 
 
 
 
 
return 0; 
}
char isVowel (char letter)
{
switch (letter)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
    return 1; 
    break;
    return 0;
}
}
Last edited by admin II : 09-May-2008 at 04:38. Reason: Please surround your C++ code with [cpp] your code [/cpp]
  #2  
Old 07-May-2008, 20:26
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 956
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Function program: getting "error C2064:"


There is a local (unused) variable also named 'isVowel'. The local variable name will take precedence, and locally, that name (or symbol) is not a function.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 07-May-2008, 21:14
lilballeer lilballeer is offline
New Member
 
Join Date: May 2008
Posts: 16
lilballeer is on a distinguished road

Re: Function program: getting "error C2064:"


Hello

thanks


I fixed the problem... and now the program runs, but it says that everything is a vowel....


I tried playing around with it. and this is the code that works best, but still not correctly:

CPP / C++ / C Code:
#include <iostream>
 
using namespace std;
char isVowel (char letter);
int main()
{
 
 
    //Michael Casey; 5/7/08
 
    char letter; 
    char letterval;
    char funcisVowel;
 
 
cout << "Enter a letter: " << endl; 
    cin >> letter;
 
 
 
 
letterval = isVowel (letter); 
 
if (letterval == 1)
    cout << "The letter is a vowel " << endl;
else if (letterval == 0) 
cout << "The letter is not a vowel" << endl; 
else 
cout << "Not a vaild selection" << endl; 
 
 
 
 
 
 
return 0; 
}
char isVowel (char letter)
{
switch (letter)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
    return 1; 
    break;
    return 0;
}
}
Last edited by admin II : 09-May-2008 at 04:38. Reason: Please surround your C++ code with [cpp] your code [/cpp]
  #4  
Old 07-May-2008, 22:54
zatora zatora is offline
New Member
 
Join Date: May 2008
Posts: 25
zatora is on a distinguished road

Re: Function program: getting "error C2064:"


Quote:
Originally Posted by lilballeer
Hello

thanks


I fixed the problem... and now the program runs, but it says that everything is a vowel....


I tried playing around with it. and this is the code that works best, but still not correctly:

#include <iostream>

using namespace std;
char isVowel (char letter);
int main()
{


//Michael Casey; 5/7/08

char letter;
char letterval;
char funcisVowel;


cout << "Enter a letter: " << endl;
cin >> letter;




letterval = isVowel (letter);

if (letterval == 1)
cout << "The letter is a vowel " << endl;
else if (letterval == 0)
cout << "The letter is not a vowel" << endl;
else
cout << "Not a vaild selection" << endl;






return 0;
}
char isVowel (char letter)
{
switch (letter)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return 1;
break;
return 0;
}
}
this is a short and easy way to do it, my advise don't complicate the simple tasks unless u r required to have a value return function but why do u need
this statement any way: letterval = isVowel (letter);
even if u r equired to use a return value function;
CPP / C++ / C Code:
#include<iostream>
using namespace std;
void isVowel(char& ch);
int main()
{
char input;
cout<<"Please enter a letter ?"<<endl;
cin>>input;
isVowel(input);
return 0;
}
void isVowel(char& ch)
{
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout<<"the Letter you have entred is vowel."<<endl; 
break;
cout<<"The letter you have entred is consonant."<<endl;
}

  #5  
Old 07-May-2008, 23:34
lilballeer lilballeer is offline
New Member
 
Join Date: May 2008
Posts: 16
lilballeer is on a distinguished road

Re: Function program: getting "error C2064:"


Quote:
Originally Posted by zatora
this is a short and easy way to do it, my advise don't complicate the simple tasks unless u r required to have a value return function but why do u need
this statement any way: letterval = isVowel (letter);
even if u r equired to use a return value function;
CPP / C++ / C Code:
#include<iostream>
using namespace std;
void isVowel(char& ch);
int main()
{
char input;
cout<<"Please enter a letter ?"<<endl;
cin>>input;
isVowel(input);
return 0;
}
void isVowel(char& ch)
{
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout<<"the Letter you have entred is vowel."<<endl; 
break;
cout<<"The letter you have entred is consonant."<<endl;
}



Hey,

Thanks, I do need it to be a value-returning function. Is the example that you posted a value-returning function??
i added the: letterval = isVowel (letter); statement because that is how i learned to use the functions.
  #6  
Old 07-May-2008, 23:47
zatora zatora is offline
New Member
 
Join Date: May 2008
Posts: 25
zatora is on a distinguished road

Re: Function program: getting "error C2064:"


all u need to di is change the void function to return value function i will post it gimme about 10 min
  #7  
Old 07-May-2008, 23:50
zatora zatora is offline
New Member
 
Join Date: May 2008
Posts: 25
zatora is on a distinguished road

Re: Function program: getting "error C2064:"


functions are two types void which can return more than one value and return functions which can return only one value so i used a void but i will post the same solution with a return type function and u can see the difference
  #8  
Old 07-May-2008, 23:58
zatora zatora is offline
New Member
 
Join Date: May 2008
Posts: 25
zatora is on a distinguished road
Smile

Re: Function program: getting "error C2064:"


ry this and tell me about it
CPP / C++ / C Code:
#include<iostream>
using namespace std;
bool isVowel(char& ch);
int main()
{
char input;
cout<<"Please enter a letter ?"<<endl;
cin>>input;
isVowel(input);
	switch(isVowel(input))
	{
	case true :
	cout<<"the Letter you have entred is vowel."<<endl; 
	case false:
	cout<<"The letter you have entred is consonant."<<endl;
	}
// u can use an int function to return 1 or 0 as u did .
return 0;
}
bool isVowel(char& ch)
{
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return true; 
break;
return false;
}
}
  #9  
Old 08-May-2008, 08:04
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 956
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Function program: getting "error C2064:"


The switch is working against you, as there is no 'default' case so the 'return 1' is always given. Try the switch reworked like this:
CPP / C++ / C Code:
switch (letter)
{
   case 'a':
   case 'e':
   case 'i':
   case 'o':
   case 'u':
      return 1;
   
   default:
      return 0;
}
Personally, though, and many would agree that it is usually better to only have ONE return point from a function, if possible.
I would have probably coded the isVowel() function like this:
CPP / C++ / C Code:
bool isVowel( char letter )
{
     bool vowel_check = false;

     switch (letter)
     {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
           vowel_check = true;
           break;
   
        default: // 'vowel_check' is still false.
           break;
     }

     return vowel_check;
}
HTH
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #10  
Old 08-May-2008, 08:20
zatora zatora is offline
New Member
 
Join Date: May 2008
Posts: 25
zatora is on a distinguished road

Re: Function program: getting "error C2064:"


this is how i coded it at the begining but i replied to lilballeer cuz he needs a return value function.
also i need to know what u mean by the switch is working against me cuz i did that function kinda in a hurry so i forget about the break statement and this the original code
CPP / C++ / C Code:
#include<iostream>
using namespace std;
void isVowel(char& ch);
int main()
{
char input;
cout<<"Please enter a letter ?"<<endl;
cin>>input;
isVowel(input);
return 0;
}
void isVowel(char& ch)
{
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout<<"the Letter you have entred is vowel."<<endl; 
break;
cout<<"The letter you have entred is consonant."<<endl;
}
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 53 23-May-2008 23:36
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
Flex and bison coding lucky88star C++ Forum 5 24-Dec-2007 11:57
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 16:19
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:15.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.