LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2003, 03:33 AM   #1
herbie_52
LQ Newbie
 
Registered: May 2003
Posts: 2

Rep: Reputation: 0
Question arithmetic operators in Kylix3 (C++)


Hi,

When I run a console-app, written in C++ on Borland Kylix - platform = Mandrake 9.0/Intel Celeron - I notice that arythmetic operators used with anything else than integers just don't work.

It seems i can only calculate with ints.
As far as i know all the usual headerfiles are in /usr/include.
Anyway, iostream (iostream.h) should do, no?

I added /usr/include, /usr/include/C++/3.2 , /lib, /lib/include and some other paths in different options of the IDE.

But.....this makes no difference.

I'm new to Kylix (and relatively new to Linux) but I really like this IDE. But if i can only use ints , then of course its useless.

I surely must have overlooked something. Anybody an idea ?

Thanx



 
Old 05-22-2003, 04:19 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
Maybe if you were a bit more specific,
like posting the snippet that doesn't work?

Cheers,
Tink
 
Old 05-23-2003, 07:36 AM   #3
herbie_52
LQ Newbie
 
Registered: May 2003
Posts: 2

Original Poster
Rep: Reputation: 0
well, it's a general problem really.

As long as I use ints in my code, no problem.
But if i use longs, floats or doubles the built application will simply not perform the calculations.

Any example will do, so I taken the calculation of the average in an array of longs.

#include <iostream.h>

using namespace std;

const int size = 5;

int main(){
long array[size] = {x , x, x, x, x } ; //where x is a long
double avg = 0.0;
long res = 0;

for(int i = 0; i < size; i++){
res += array[i];
}

avg = static_cast <double>(res) / size;

cout << avg << endl;

return 0;
}

OK, if i compile this piece of code , I just get the output : " 0 ";
Which means the calculations is just not done and the variable avg just keeps its initial value.

I'm really starting to wonder if this is not a general linux problem.
I have this problem on a laptop running Mandrake 9.
On a desktop running Mandrake 8.1 i also use Kylix and there i don't have this problem.
The thing is, i can't always work on my desktop, and i'm not so experienced in both linux and C++ , so i really prefer an IDE over the gcc .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple arithmetic in bash gfrair Linux - Newbie 9 03-16-2005 02:09 PM
Operators *^ and >> GodSendDeath Programming 4 11-01-2004 09:47 PM
operators linuxanswer Programming 3 12-14-2003 06:09 PM
Bash, non-integers and arithmetic causticmtl Programming 5 07-16-2003 09:15 AM
Basic Java arithmetic question chr15t0 Programming 2 07-05-2003 01:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration