473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Return value

I am very new to C/C++, my instructor asked us to take the follwing code below and translate it into C/C++. I translated it in the code furthest down. Now my instructor says im on the right track, i just need a return value.

This is code being translated



Expand|Select|Wrap|Line Numbers
  1. public object andd(operand1, operand2)
  2. {
  3.     object functionReturnValue = null;
  4.     dynamic result = null;
  5.     result = invalid;
  6.     if (operand1 == preferred) {
  7.         if (operand2 == preferred) {
  8.             result = preferred;
  9.         }
  10.     }
  11.     if (operand1 == preferred) {
  12.         if (operand2 == other) {
  13.             result = other;
  14.         }
  15.     }
  16.     if (operand1 == other) {
  17.         if (operand2 == preferred) {
  18.             result = other;
  19.         }
  20.     }
  21.     if (operand1 == other) {
  22.         if (operand2 == other) {
  23.             result = other;
  24.         }
  25.     }
  26.     functionReturnValue = result;
  27.     if (Trace)
  28.         traceAdd("andd");
  29.     return functionReturnValue;
  30. }


This is what i translated the above code in, just need help with return value


Expand|Select|Wrap|Line Numbers
  1. #define preferred ‘l’
  2. #define other ‘o’
  3. #define invalid ‘x’
  4.  
  5. char andd( char operand1, char operand2)
  6. {
  7.      char result=invalid;
  8.      if (operand1 == preferred) {
  9.            if (operand2 == preferred) {
  10.                  result = preferred;
  11.            }
  12.      }
  13.      if (operand1 == preferred) {
  14.            if (operand2 == other) {
  15.                  result = other;
  16.            }
  17.      }
  18.      if (operand1 == other) {
  19.            if (operand2 == preferred) {
  20.                  result = other;
  21.            }
  22.      }
  23.      if (operand1 == other) {
  24.            if (operand2 == other) {
  25.                  result = other;
  26.            }
  27.      }
Nov 28 '14 #1
4 1741
weaknessforcats
9,208 Expert Mod 8TB
What's wrong with the return value?

The result is a char, the function returns a char.
Nov 28 '14 #2
Thats what i was trying to figure out, he told me that it is missing a return value.
Nov 30 '14 #3
Rabbit
12,516 Expert Mod 8TB
Your second set of code is missing lines 26-30 of the first set of code.
Nov 30 '14 #4
In the original code, you returned functionReturnValue. In the new code, you are not return anything..
Dec 12 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dave | last post by:
Hi, I tried something with 'return value' of a function and i got two different behaviours. My question is: why does method 1 not work? Thanks Dave method 1: here, whatever i choose (ok or...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
5
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
2
by: Eric Lilja | last post by:
Hello, consider this complete program: #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Hanna {
7
by: Rudy | last post by:
Hello All! I have a value in a textbox(txbTableIDm.Text ) that I would like to use in a paremiter in a SP I wrote, and then have the select statement work off that parememter, retireive a...
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
4
by: Jeff | last post by:
Hey ..NET 2.0 I have a stored procedure which calculates a value and return that value. I'm wondering if I should use ExecuteNonQuery, ExecuteScalar or ExecuteReader on this stored...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.