Nissan Titan Forum Left Header Nissan Titan Forums Right Header
Go Back   Nissan Titan Forum > Off-Topic Area > Off-Topic Discussion

Off-Topic Discussion Discussion of Off-Topic items.

   
       

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 10-29-2007, 04:31 PM   #1 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
to all you c++ programmers out there...

I need some help.

In my college class were learning functions right now and im trying to write a program that takes a set of integers (aka 1,2,3,4,5) and displays them backwards.

I think i got it but im getting a syntax error that says: c:\ctheurer05\ctheurer05\ctheurer05.cpp(30) : error C2106: '=' : left operand must be l-value.

What does it mean by it must be l-value?
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving
imaweirdo159 is offline   Reply With Quote
Old 10-29-2007, 04:48 PM   #2 (permalink)
Registered User
iTrader: (2)
 
Energizer's Avatar
 
Join Date: Jul 2007
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

if its an array of integers or pointers to integers, just index the array backwards...

PS: it helps if you can post your source, otherwise we're just guessing.... also-- what compiler you using?

Last edited by Energizer; 10-29-2007 at 04:50 PM.
Energizer is offline   Reply With Quote
Old 10-29-2007, 04:51 PM   #3 (permalink)
Registered User
iTrader: (0)
 
grnTitan04's Avatar
 
Join Date: Jan 2007
Location: Painesville, OH
Posts: 563
Thanks: 6
Thanked 1 Time in 1 Post
Re: to all you c++ programmers out there...

I can help you A LOT more with a text copy of the code, just paste it in here or something, but it sounds like you need ==. (Test for equality) that, or the data type of your pointer is wrong.
__________________
Improvements:
K&N Drop in, Magnaflow muffler, Step Tubes, Reese Hitch, Husky Liners, Nitto Terra Grapplers 285/70/17
Air Box mod, Improved Fog Light Mod, dba 4000 series rotors, Akebono ProACT pads, Extang RT Tonneau, RadFlo Remote Res Rears, OEM Hood Deflector



Wish List: Air Horn, RadFlo 2.0 Coilovers, AEM Brute Force CAI, TruTrac, Bass boat...
Donations graciously accepted.
grnTitan04 is offline   Reply With Quote
Old 10-29-2007, 05:04 PM   #4 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

Im using visual studio 2005.

And i thought i needed == as well, but when i did that it gave me a similar error- c:\ctheurer05\ctheurer05\ctheurer05.cpp(24) : warning C4553: '==' : operator has no effect; did you intend '='?

heres the function with the errors in it:

void reverse (int number)
{
int a, b, c, d;

1234 % 10 = a;

1234 % 100 / 10 = b;

1234 % 1000 / 100 == c;

1234 % 10000 / 1000 == d;

a, b, c, d == number;
}
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving
imaweirdo159 is offline   Reply With Quote
Old 10-29-2007, 05:16 PM   #5 (permalink)
Registered User
iTrader: (0)
 
grnTitan04's Avatar
 
Join Date: Jan 2007
Location: Painesville, OH
Posts: 563
Thanks: 6
Thanked 1 Time in 1 Post
Re: to all you c++ programmers out there...



Well, there are a number of things wrong with this. I need a better explanation of what a,b,c,d is and (I assume from the syntax you are supposed to write your very own function) so I need you to describe what it is that you want to pass to your function and what you want it to do with that variable.
What is the format of the data you are being presented to sort? (Array, stringlist, read from a file?)

To answer the question of 'what is the errorhandler trying to tell me?':
1234 % 10 = a; // does nothing
a = 1234 % 10; // assigns the value of the calc to a
but this calculation doesn't make any sense.

Is there any chance you are trying to sort by number of digits?
grnTitan04 is offline   Reply With Quote
Old 10-29-2007, 05:21 PM   #6 (permalink)
Registered User
iTrader: (0)
 
grnTitan04's Avatar
 
Join Date: Jan 2007
Location: Painesville, OH
Posts: 563
Thanks: 6
Thanked 1 Time in 1 Post
Re: to all you c++ programmers out there...

Also,
If the function should return something, it is not void, void means don't return anything. If that is what you want, then at the end, it should be number = something. If you want to just return the result (maybe easier?) then put return(number); after the number = line and chance the function definition line to int reverse(whatever...
grnTitan04 is offline   Reply With Quote
Old 10-29-2007, 05:27 PM   #7 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

Quote:
Originally Posted by grnTitan04

What is the format of the data you are being presented to sort? (Array, stringlist, read from a file?)
Im not exactly sure what you're asking. What i did was just took the number 1234 and im trying to write a function (i know its the complicated way to do it, but thats the assignment) that will print 4321 to the screen.

To answer the question of 'what is the errorhandler trying to tell me?':
1234 % 10 = a; // does nothing
a = 1234 % 10; // assigns the value of the calc to a
but this calculation doesn't make any sense.
Yeah, i caught that i had my variables backwards...oops. But by getting the modulus of 1234 (aka 1234/10= 123 remainer 4) i am getting rid of the other digits to just get 4, then inserting 4 into the variable a.

Is there any chance you are trying to sort by number of digits?
Not necessarily sorting by the number of digits, but yes i am sorting the digits.
Thanks for the help this far, i tried to answer the questions as best i could in bold above.

EDIT: In reply to the void stuff. To return the integer backwards is actually a different problem. The book specifically said to start my assignment with void reverse(int number).
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving

Last edited by imaweirdo159; 10-29-2007 at 05:35 PM.
imaweirdo159 is offline   Reply With Quote
Old 10-29-2007, 05:36 PM   #8 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

I think i may have found my problem...i may be reading the assignment wrong. Ive been thinking that they wanted number to be a variable but the example they give ("For example, reverse(3456) displays 6543.") its looking like they want me to insert the number there. Ill mess with the code a bit and get back to you guys.

Thanks again for the help this far!
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving
imaweirdo159 is offline   Reply With Quote
Old 10-29-2007, 05:45 PM   #9 (permalink)
Registered User
iTrader: (0)
 
grnTitan04's Avatar
 
Join Date: Jan 2007
Location: Painesville, OH
Posts: 563
Thanks: 6
Thanked 1 Time in 1 Post
Re: to all you c++ programmers out there...

OOOOOOOOOOOOOoooooooooookay.
I understand the assignment now.

You are on the right track, though your approach is a little cumbersome.
So in the example, 1234 will be replaced by 'number'.

Be careful of rounding errors, I might use a rounding function to force predictable results. I don't know how far you are in this coding thing yet, but in case you don't know the limits of number, you might write something that does not need to know. ie
while (number > 0) AND index < ubound(array)
do
array[index] = number%10
number = number - array[index] / 10 //which will fix rounding for all cases
index++

Or something like that.
That would be limited by the size of the array only, not the size of the number you passed.
the other advantage to putting them in the array is that you can just retain the last index you used and start there, -1 each time, poof, numbers in reverse.

Let me know if you need more help, I been there.
And I taught C++ for 2 years in college, so I am only a little full of $hit.
grnTitan04 is offline   Reply With Quote
Old 10-29-2007, 06:44 PM   #10 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

Thanks everybody for the help! I fixed it and it compiles and works beautifully now!

#include <iostream>
using namespace std;

void Reverse(int);

int main()
{

cout << "This program displays an integer reversed." << endl;

cout << "Enter the 4 digit integer you wish to have reversed." << endl;

int number=0;

cin >> number;

Reverse(number);

}
void Reverse(int number)
{
int a, b, c, d;

a = number % 10;

b = number% 100 / 10;

c = number % 1000 / 100;

d = number % 10000 / 1000;

cout << a << b << c << d <<endl;

}
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving

Last edited by imaweirdo159; 10-29-2007 at 06:59 PM.
imaweirdo159 is offline   Reply With Quote
Old 10-29-2007, 07:37 PM   #11 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

Quote:
Originally Posted by grnTitan04
OOOOOOOOOOOOOoooooooooookay.
I understand the assignment now.

You are on the right track, though your approach is a little cumbersome.
So in the example, 1234 will be replaced by 'number'.

Be careful of rounding errors, I might use a rounding function to force predictable results. I don't know how far you are in this coding thing yet, but in case you don't know the limits of number, you might write something that does not need to know. ie
while (number > 0) AND index < ubound(array)
do
array[index] = number%10
number = number - array[index] / 10 //which will fix rounding for all cases
index++

Or something like that.
That would be limited by the size of the array only, not the size of the number you passed.
the other advantage to putting them in the array is that you can just retain the last index you used and start there, -1 each time, poof, numbers in reverse.

Let me know if you need more help, I been there.
And I taught C++ for 2 years in college, so I am only a little full of $hit.
Arrays are the next chapter....so expect to see me back! haha
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving
imaweirdo159 is offline   Reply With Quote
Old 10-30-2007, 04:58 AM   #12 (permalink)
Registered User
iTrader: (2)
 
Energizer's Avatar
 
Join Date: Jul 2007
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

I see what you were trying to do now... but you hard-coded your problem to require exactly 4 digits... and your function didn't perform as a function (it acted like a procedure), although it technically returns void.

have you learned the shift operators yet?


Quote:
Originally Posted by imaweirdo159
Thanks everybody for the help! I fixed it and it compiles and works beautifully now!

Code:
 
#include <iostream>
using namespace std;
 
void Reverse(int);
 
int main()
{
   cout << "This program displays an integer reversed." << endl;
   cout << "Enter the 4 digit integer you wish to have reversed." << endl;
 
   int number=0;
 
   cin >> number;
 
   Reverse(number);
}
 
void Reverse(int number)
{
   int a, b, c, d;
   a = number % 10;
 
   b = number% 100 / 10;
 
   c = number % 1000 / 100;
 
   d = number % 10000 / 1000;
 
   cout << a << b << c << d <<endl;
}

Last edited by Energizer; 10-30-2007 at 05:00 AM.
Energizer is offline   Reply With Quote
Old 10-30-2007, 01:53 PM   #13 (permalink)
Registered User
iTrader: (0)
 
imaweirdo159's Avatar
 
Join Date: Jan 2007
Location: St. George, UT
Posts: 163
Thanks: 0
Thanked 0 Times in 0 Posts
Re: to all you c++ programmers out there...

Quote:
Originally Posted by Energizer
I see what you were trying to do now... but you hard-coded your problem to require exactly 4 digits... and your function didn't perform as a function (it acted like a procedure), although it technically returns void.

have you learned the shift operators yet?
Yeah i didnt realize that the assignment was saying that i had to get user input, so that changed things up a bit.

Uhm i think weve talked about them, but not really gone over them. Gimme an example.
__________________
2004 Titan KC XE, 4x4, Preferred Pkg, OR, PRG 2" leveling kit, Cooper Discovery STT 33x12.50xR17LT tires on some Ultra Thunder 17x8 wheels.

Next Upgrade: Either trade in for a new one, or fix everything on this one...

Wheels, Tires, and a Lift. Dont bother me, im driving

Last edited by imaweirdo159; 10-30-2007 at 02:05 PM.
imaweirdo159 is offline   Reply With Quote
Reply






Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
chips or programmers??? afailedutopia Titan Performance Modifications 3 06-08-2007 06:56 AM
Update on Hypertech Programmers???? Scooby Titan Performance Modifications 5 07-22-2006 08:02 PM
weres the programmers computer chips something Brian mc Titan Performance Modifications 13 01-24-2005 12:03 PM


All times are GMT -7. The time now is 03:27 PM.


  • AutoForums.com
  • Truck
  • European
  • Import
  • Domestic
  • Manufacturer

AutoForums.com is the premier network of enthusiast-owned enthusiast-operated automotive communities.
We operate more than 100 automotive forums where our users consult peers for shopping information and advice, and share experiences and opinions as a community.

Visit AutoForums.com today.

For advertising information, please visit our AutoForums.com website and Contact Us, or send an email message to sales@autoforums.com.