lvalue question [solved]


 
Thread Tools Search this Thread
Top Forums Programming lvalue question [solved]
# 1  
Old 12-27-2011
lvalue question [solved]

Hi,

This code was originally to print a sine function table. I modified it to print a tangent function table. I got an "lvalue" error which I can't solve...Any hint on why am I getting this error?

Here is the code:
Code:
// sintab.cpp
// Creates a tangent function table
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

#define PI      3.1415926536
#define START   0.0                      // Lower limit
#define END     (2.0 * PI)               // Upper limit
#define STEP    (PI / 8.0)               // Step width
#define HEADER  (cout << " ***** Tangent Function Table *****\n\n")
int main()
{
  HEADER;                                // Title
                                         // Table Head:
  double x;
  cout << setw(16) << "x" << setw(20) << "tan(x)\n"
       << "-----------------------------------------"
       << fixed << endl;
  
  for( x = START; x < END + STEP/2; x += STEP)
    {
      if ( x = 0.5 * PI || x = 1.5 * PI )
        cout << "tangent is undefined." << endl;
      else
        cout << setw(20) << x << setw(16) << tan(x) << endl << endl << endl;
    }
  return 0;
}

---------- Post updated 12-27-11 at 02:42 AM ---------- Previous update was 12-26-11 at 11:30 PM ----------

OK I got it. It's a stupid mistake, I should have used
Code:
if ( x == 0.5 * PI || x == 1.5 * PI )

instead of the one used above.
# 2  
Old 12-27-2011
That might not evaluate in the order you think it does.

Code:
(( x == (0.5 * PI)) || (x == (1.5 * PI) ))

# 3  
Old 12-27-2011
Thanks

Yes!

It's a typo. Sorry for that!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[solved] Awk/shell question to parse hour minute from text

Hi, I have a quick question on parsing the hour/minute and value from a text file and remove the seconds portion. For example in the below text file: 20:26:01 95.83 20:27:01 96.06 20:28:01 95.99 20:29:01 7.11 20:30:01 5.16 20:31:01 8.27 20:32:02 9.79 20:33:01 11.27 20:34:01 7.83... (2 Replies)
Discussion started by: satishrao
2 Replies

2. Solaris

[Solved] Question changing timezone rules / zic

Dear, One of our customer which is located in Iraq/Baghdad, has informed us about a official change in daylight saving time in few days later and has asked us to fix this issue. So, the current timezone of that system is set as 'Asia/Baghdad' which is correct. however to fix the issue I went... (0 Replies)
Discussion started by: Anti_Evil
0 Replies

3. Shell Programming and Scripting

[Solved] Question for Perderabo on date calc

Hi, First of all, thanks for all the awesome suggestions on this forum. This helps all the UNIX enthusiast like me. Now, I had a similar requirement as mentioned in a very old post here: Question about Perderabo's "Days Elapsed Between Two Dates" But I am struggling what to change in the... (5 Replies)
Discussion started by: CleoBos
5 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Perl Question - split function with csv file

Hi all, I have a csv file that appears as follows: ,2013/03/26,2012/12/26,4,1,"2017/09/26,5.75%","2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1",,,2012/12/26,now when i use the split function like this: my @f = split/,/; the split function will split the data that is... (2 Replies)
Discussion started by: WongSifu
2 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Copy question

I was reading man for cp, and I found the option cp -d. What does it mean? According to the documentation -d is the same as --no-dereference --preserve=link. I understand that --preserve preserves the attributes of the file such as time stamp, but I have no clue about neither --preserve=link... (2 Replies)
Discussion started by: santiagorf
2 Replies

6. Homework & Coursework Questions

Compiler error "lvalue required as left operand of assignment"

1. After trying to compile code error is given Lvalue required as left operand of assignment. 2. Relevant commands, code, scripts, algorithms: if , else if 3. The attempts at a solution (include all code and scripts): /* File: incircles.cpp Created by: James Selhorst ... (2 Replies)
Discussion started by: c++newb
2 Replies

7. Shell Programming and Scripting

[solved] Question for using variables outside a while loop

I want to get newvar outside the while any ideas? while read myline; do var=${myline} newvar1=$(let "$var") done echo $newvar1 I found it its ok now Thank you! (0 Replies)
Discussion started by: sanantonio7777
0 Replies

8. UNIX for Dummies Questions & Answers

Basic Question on perl use POSIX [SOLVED]

Hi guys, I think this is a basic question. I'm not very familiar with this. I'm trying to round a number up and round a number down. From what I have read this can be done using POSIX. I have tried to to use this, but i'm getting errors: sub findGridBounds($$$%) { use POSIX; ... (0 Replies)
Discussion started by: WongSifu
0 Replies

9. Programming

lvalue required as left operand of assignment

z < 0 ? z= z + 2*r*cos(theta) : z= z - 2*r*cos(theta); Does anyone know what is wrong here? I've got compiler msg: lvalue required as left operand of assignment All variables are "double". I'm using gcc compiler (but I don't think that matters) (5 Replies)
Discussion started by: EmilyTheStrange
5 Replies

10. Programming

Need help compiling in C: lvalue required as left operand of assignment

Hi, I am trying to compile a program (not coded by me), and i'm getting this error: 203: error: lvalue required as left operand of assignment As you may be guessing, the program doesn't compile, the line number 203 is the following: ... (2 Replies)
Discussion started by: Zykl0n-B
2 Replies
Login or Register to Ask a Question