Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,395 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,118 people online right now. Registration is fast and FREE... Join Now!




Non-Void Function

 
Reply to this topicStart new topic

Non-Void Function

WsaENoTsoCK
22 Sep, 2006 - 07:32 AM
Post #1

New D.I.C Head
*

Joined: 6 Sep, 2006
Posts: 4


My Contributions
Hey Dudes, I got this warning that i can't seem to resolve can anyone give me any pointers.
The afflicated code is as follows:

CODE

int prior(char ch)
{
    switch(ch)
    {
         case '/' :
         case '*' :
              return '4';
              break;                                            
         case '+' :
         case '-' :
              return '3';
              break;
    }
}


the warning shown is as follows:

QUOTE
control reaches end of non-void function


I do thank you in advance

This post has been edited by Dark_Nexus: 26 Sep, 2006 - 11:04 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Non-Void Function
22 Sep, 2006 - 07:36 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
With no default case, if one of the items supplied does not match, no value will be returned. Also, you have specified an integer return value, yet you are returning a char...is that your intent?
User is offlineProfile CardPM
+Quote Post

WsaENoTsoCK
RE: Non-Void Function
22 Sep, 2006 - 07:41 AM
Post #3

New D.I.C Head
*

Joined: 6 Sep, 2006
Posts: 4


My Contributions
Oops stupid me. So there must be a default for switch. Arghz!!!!!

CODE


int prior(char ch)
{
    switch(ch)
    {
         case '/' :
         case '*' :
              return 4;
              break;                                            
         case '+' :
         case '-' :
              return 3;
              break;
         default:
              return 0;
    }
}



Hope this helps anyone to be not as stupid as me

This post has been edited by WsaENoTsoCK: 22 Sep, 2006 - 07:44 AM
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Non-Void Function
22 Sep, 2006 - 09:33 AM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,935



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Although the compiler does issue a warning, a character is stored as a number ie. it can also be treated as an integer.
So instead of returning 0, it would return it's ASCII Value which is 48.
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: Non-Void Function
22 Sep, 2006 - 10:05 PM
Post #5

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
48 = number 48
'3' = Referes to the ASCII table, in this case : The number "0"
"48" = Prints it out as a character.

ASCII Here
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:52AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month