necrolin 94 Posting Whiz in Training

Well, you set n to zero on line 7 (n = 0;) and then you never change it so it's obviously still zero. Remember that == checks for equality. It does not set num to equal anything. Therefore, num==a; should be num = a; and then continue the same pattern on lines 9-11.

necrolin 94 Posting Whiz in Training

You declare a variable with the name "rand" and then you try to call the function rand. It thinks you are trying to use the int variable as a function. Delete the rand variable or at least rename it and it works fine.

necrolin 94 Posting Whiz in Training

I thought there was the thing in C++ where constant variables were generally optimized away and treated as #defines.

You're right and they are expanded in place where possible. But for this to be possible you must know what the value will be at compile time, you cannot implicitly or explicitly pass the address of the constant, it has to be simple enough to work with the compiler's symbol table, etc.

However, Ancient Dragon and Tetron gave reasons for why the code may not in fact be faster. So, the final answer is still "it depends."

necrolin 94 Posting Whiz in Training

If the value of pitch is not known at compile time then storage is required and the code will not be more efficient. The only benefit you will get is that of the added safety of not being able to accidentally change the variable during run time.

necrolin 94 Posting Whiz in Training

I'm being lazy so I'll just quote page 337 of "Thinking in C++":

"As a matter of practice, if you think a value shouldn't change, you should make it a const. This not only provides insurance against inadvertent changes, it also allows the compiler to generate more efficient code by eliminating storage and memory reads."

Basically the compiler tries to avoid allocating storage for const where possible, which in turn creates more efficient code.

necrolin 94 Posting Whiz in Training

First thing I noticed was:

string filename = "names.txt"; // Create Var to hold file name
   inFile.open("name.txt");

Why are you creating a variable and then not using it?

About your include "cmath", so far you don't really need it.

Part 1 works fine. I was thinking that you could simplify your code in the long run by reading everything into your data structure and then from there you can use a single loop to to display the contents to the screen and output it to a file. Otherwise you'll have to read the file again so that you can put the data into the data structure, which seems like unnecessary work if you ask me.

necrolin 94 Posting Whiz in Training

wxDevCpp and Kdevelop don't as far as I know.

wxDevCPP is just an extension of DevCPP which came with MingW. According to their website (on the FAQ page):

"We use the MingW compiler that comes with Dev-C++."

Which would seem to indicate that they are shipping with a rather old version of MingW as DevC++ hasn't been updated in years.

KDevelop seems to only have packages for Linux/Solaris in the downloads directory. They claim to have a Windows version, but I wasn't able to find one. (Maybe I just didn't look hard enough.)

necrolin 94 Posting Whiz in Training

It's your copy constructor.... remove it and it will work.

necrolin 94 Posting Whiz in Training

You'll have to install whatever libraries provide you with these "missing" headers. They do not come with Visual Studio, nor do I believe they are a part of the C++ standard. itpp/itcomm.h appears to be part of the IT++ Communications library. Google the header files and you should be able to find what you're looking for.

necrolin 94 Posting Whiz in Training

If I understand you correctly then you want to skip all the blank lines in your file. What you'll see with getline() is that it reads the next line in the input file regardless of whether it is full or blank. Therefore, you will get blank lines in your output. You can use a quick if statement to test whether what getline() read is blank or not.

Here's a quick example:

string data;
    while (getline(inputFile, data))
    {
        if (data == "") continue; //Skip blank line

        cout << data << endl;
    }

In this example, "continue" will restart the loop while the input is blank and therefore, skip all the blank lines.

(Of course you'll have to modify the code to work with your program, but the basic idea is there.)

necrolin 94 Posting Whiz in Training

Part of this program doesn't make much sense to me. First, you have:

double axx1;
float xx1 = 0;

Then you do some calculations and then:

axx1=xx1;

Converting from a float to a double doesn't do anything at all for you. If you want more precision then why don't you just use doubles all the way through the program? I believe that the math functions that you use (sin, cos, tan) can take floats, doubles, and long doubles so you'll be fine and you'll get an answer that's closer to what you're looking for due to the extra precision that you'll get.

You may also consider formatting the output to limit the number of digits after the decimal.

necrolin 94 Posting Whiz in Training
int t[10];
while(cin >> t[10])

Be careful. You declare an array of size 10. This will begin at t[0] and go up to t[9]. You're trying to put data into location t[10] which isn't part of the array. This may crash your program.

What I assume you want to do is to enter 10 integers into the array. To do this use a for loop like this:

for (int i = 0; i < 10; i++)
{
    cout << "Enter next integer: "; //Don't really need this line
     cin >> t[i];
}
necrolin 94 Posting Whiz in Training

Thanks I have tried that before, however I am looking for the stylus, pen support by linux so I can draw, write on the screen in linux programs, I don't think that is widely support or has software for it. See: http://en.wikipedia.org/wiki/Tablet_pc#Linux

I think there is no support by open office so I may still need to use windows office. What else could I do? Can someone build a os that will work or develop one?

The report that I read clearly stated that the stylus was automatically detected and configured by the latest version of Ubuntu. Can't help you much more than that though, sorry. I don't use a stylus, but I have seen them used with Linux. I don't think that Ubuntu includes the program for inputing your writing by default so it's something that you may need to search for it in the repositories. Wish I could be more helpful.

necrolin 94 Posting Whiz in Training

i apologize for that but I just thought this was kind of rude...

Very good. I repeat:




Originally Posted by WaltP View Post

What function are you calling to actually perform the wait?

The sleep() function was used in the post that I linked to. It uses milliseconds as a base wait period. So you can do Sleep(1000); for example.

necrolin 94 Posting Whiz in Training

According to the book "Thinking in C++" the second example is the "old" way of doing things while static_cast<> is the "new" way. So, the old way would be the kind of code you'd see in C while the static cast would be the C++ way of doing things. (From pg 169)

necrolin 94 Posting Whiz in Training

It's because the packages would have been updated since the official release. You should update your software listing before installing new software. This way you ensure that what your package manager has listed as available software is in sync with what's on the servers.

Another way to look at it is imagine that locally your computer thinks that it should install Apache-2.0.deb (version 2.0), but the servers have been updated to Apache-2.5.deb (version 2.5). The package manager should indicate that something's wrong in this case because it can't install the version that it thinks it should install.

necrolin 94 Posting Whiz in Training

I don't have this tablet PC, but I did do a Google search for you. Users are reporting that all is working fine with Ubuntu. One thing to keep in mind is that Ubuntu is distributed as a live CD so you can try it out before installing it just to make sure that everything works for you.

As far as "as good or better" is concerned I suppose that it depends on what you do. Windows is better suited for some tasks while Linux is better suited, in my opinion at least, for others. I recommend downloading Ubuntu and giving it a test run. All it will cost you is some bandwidth and a blank CD. If you like it then install it. If you don't then give the CD away and your Windows install machine will still be just the way you left it.

necrolin 94 Posting Whiz in Training

Ubuntu has OpenOffice installed by default. If you read the error it states that what you are trying to do: Conflicts with the installed package 'openoffice.org-core'. This means that you are trying to install OpenOffice, but it's not letting you because you already have OpenOffice installed or at least part of it. If you really want to install a different version of the software then first remove the Ubuntu version (all of it) and then install the one you want to use.

Try running a search for OpenOffice in Synaptic and make sure that nothing is installed. Then you should have no conflicts.

necrolin 94 Posting Whiz in Training

Well, the website indicates that:

"IronPython is an implementation of the Python programming language running under .NET and Silverlight."

So it's safe to say that it's not for Linux. Ubuntu installs Python by default so you'll already have it installed on your computer.

necrolin 94 Posting Whiz in Training

"apt-get update" updates the list of available packages so your system knows what can actually be installed.

Did the solution work for you?

necrolin 94 Posting Whiz in Training

if u wanna be a dick dont respond to my questions

Actually what WaltP stated was correct. You're not calling any function that makes the computer wait 10 seconds. Instead of calling him names a more constructive approach would be to state that you realize that you're not calling a function to make the computer wait because you have no idea how to implement such a function yet and that's fine. No problems. But do try to be polite.

There's more than one way to implement a wait period. Here's one solution for you:

http://www.daniweb.com/forums/thread65024.html

necrolin 94 Posting Whiz in Training

I'm confused. Your question states that you want to count the number or "words" in a file, but your program is counting the number of "lines" in the file. Which one are you trying to accomplish?

That getchar() is totally useless there because you've already gotten to the end of the file and then you try to read a character, but there's nothing left to read.

My suggestions would be the following:

a) If you want to truly count the number of words in the file then do something like:

- Read the file one character at a time and count the spaces between the words
- Or read the file one word at a time and count each word.

b) If you want to count the number of lines in the file then:

while (getline(myfile, line)) { size++; }

Don't check for eof at all, because you don't need to. It will stop at the end of the file automatically, but do check if the file is open. Maybe something like " if (myfile.fail()) { cerr << "Could not open file\n"; } ".

necrolin 94 Posting Whiz in Training

What do you mean you have "no partition for /home but I have a partition for all my data files"? /home is where your data files go. It's the only place your personal data files go.

swap: Looks fine. If you have plenty of ram you'll never use it.

/: The base install is only several of gigs so 10 gigs is fine. Whether 10 gigs is big enough for you depends on how much additional software you plan on installing and how you plan on using the machine. But I think you'll be ok.

If you want to separate your data and software have 3 partitions:
/
/home (for data)
swap

necrolin 94 Posting Whiz in Training

If Putty isn't connecting then I'd assume that either Mandriva isn't configured as an SSH server or that the firewall is blocking you. Make sure that you have the ssh daemon running and that port 22 is open (or whatever other port you have configured ssh to run on).

SSH is usually command line, however you can enable X in the config file. Then you can run gui applications over the network. It's the only option that I can think or aside from vpn and rdp which you mentioned aren't options for you.

necrolin 94 Posting Whiz in Training

How about SSH? You could always use something like Putty to provide you with an SSH client for XP. http://www.putty.org/

necrolin 94 Posting Whiz in Training

My 2 favorite IDEs for Java would be Eclipse and NetBeans.

necrolin 94 Posting Whiz in Training

Are you hiring? If so my hourly is $200 USD. Send me a check and I'll send you the code. If you think that we're going to do your homework for you just because you're too lazy to do it yourself it's not going to happen. Nobody is going to do this work for you. Write the program yourself. If you get stuck somewhere along the way then send us your code and we'll help you fix it. That's what we do here. We help. This is not a homework doing agency for students that don't feel like studying. Sorry.

Salem commented: Nice +17
necrolin 94 Posting Whiz in Training

system("pause"); is not the best way to prevent the program from exiting. Using an alternative like cin.get() would be preferred.

Example:

cout << "Paused...\n";
    cin.get();
necrolin 94 Posting Whiz in Training

What kind of errors are you getting?

Your program compiles just fine in Code::Blocks using the current version of Mingw.

I'm wondering if you have Mingw installed on your computer. Could you double check for us please? There were 2 versions of DevC++, one with a compiler and the other without. You may have the one without the compiler... hence the errors. No way of knowing without reading a few of the errors though or checking your install.

Also, conio.h is not really a part of standard C/C++. Try compiling without that line and see if you have any luck. I'll quote wikipedia on that one: "conio.h is a header file used in old MS-DOS compilers to create text user interfaces. It is not part of the C programming language, the C standard library, ISO C nor is it required by POSIX."

necrolin 94 Posting Whiz in Training

hei
May I know how to handle dev cpp;

It shows error even for simple programs which I had successfully run in turbo c 3.0

Now I've never used turbo c before, but I have used Dev-C++ way back in the days when it was still under development. There are a few things that could explain why things aren't compiling. First, you could have downloaded a version of DevC++ that comes without a compiler, so it's complaining that the compiler is missing. Or you could also be doing something that is specific to Turbo C (non standard code) that won't compile on anything else. I've never used turbo c, but I've heard rumors about it on the net here and there. It's hard to tell exactly because you haven't given us much to work with.

I do agree with Ancient Dragon though. DevC++ hasn't been developed in years and it was abandoned because the authors thought that it was buggy if I remember correctly. Download something else like Code::Blocks and use that instead. You'll at least have a recent IDE and a recent version of Mingw.

necrolin 94 Posting Whiz in Training

i have a doubt regarding this....

int *pa =4

is considered unsafe isn't it?? so how does

int *p3=*p1+*p2

work properly...
ty in advance

Well, I tried to get adding pointers to pointers working every which way I could and all but one ways resulted in a compile time failure.

int *p3 = *p1 + *p2; //Does NOT compile

In fact it spits out: error: invalid conversion from `int' to `int*'

The way I did get it to compile though is to do something like this:

#include <iostream>

using namespace std;

int main()
{
    int a = 1;
    int b = 2;
    int c;
    int *p1 = &a;
    int *p2 = &b;
    
    //Create the pointer and make it point to something
    int *p3 = &c;

    //Then assign the value of the pointers to the new pointer
    *p3 = *p1 + *p2;

    cout << *p3 << endl;

    return 0;
}

If there's some other way to do this then I'd love for someone to show me, but this is the only way that I could figure out on my own.

A pointer is supposed to point to a memory location. If you do something like: int* p3 = *p2 + *p1; then which memory location is it supposed to be pointing to? There is no memory location to point to in this example. So first, set up the pointer then add the values to the existing memory location.

necrolin 94 Posting Whiz in Training

Don't encourage GUI use, the best way to learn is command line.

you can use "sudo apt-get remove [package]"
or to remove it completely(all the config files) use "sudo apt-get purge [package]"

I neither encourage nor discourage GUI use. I simply present it as an option. The user should choose what is best based on their confidence level and skill. I love the command line, but I admit that it's not for everybody. Nothing wrong with that.

necrolin 94 Posting Whiz in Training

Operator overloading is used to make it easier to read/use an object. For example, you can overload the operator << so that you can print the value associated with an object rather than using an accessor function.

Operator overloading also allows you to assign one object to another via the operator =. This ensures that everything is copied correctly from one object to another.

Templates, I'm just starting on them, but they are used when you want to make a container (or object) like a vector which can handle any type (int, double, string, whatever).

necrolin 94 Posting Whiz in Training

sudo apt-get remove "packageName"

or you could easily use of of the GUI tools to do it as well. If you want to know more about the options available in apt-get try:

man apt-get

and you'll get the manual page which lists the options for the package manager.

necrolin 94 Posting Whiz in Training
#include <iostream>

using namespace std;

int BMIF(int weight, int height);

int main()
{
int weight ; // weight in pounds
int height ; // height in inches
float BMI ; // Body Mass Index
bool DoItAgain ;
char Repeat ;

cout << " " << endl ;
cout << "Body Mass Index (BMI) Calculator" << endl ;
cout << " " << endl ;
cout << "Enter your weight in pounds. (please round to nearest whole number): " << endl ;
cin >> weight ;

cout << "Enter your height in inches. (please round to nearest whole number): " << endl ;
cin >> height ;

BMI = BMIF(weight, height);
cout << "Your BMI is" << BMI << endl ;

if (BMI < 18.5)
cout << "You are underweight, and should considered gaining weight."
"Please contact your doctor to discuss your options" << endl ;

if (BMI <= 24.9)
cout << "Congratulations, you are a healthy weight."
"You should continue to maintain this weight" << endl ;

if (BMI <= 29.9)
cout << "You are over weight and should consider losing a little bit of weight." << endl ;

if (BMI <= 39.9)
cout << "You are obese and your weight could lead to serious health problems."
"Please contact your doctor to discuss diet and exercise." << endl ;

if (BMI >= 40.0)
cout << "You are severely obese and your weight may already be causing serious health complications."
"Please contact your doctor to dicuss significant weight-loss options." << …
necrolin 94 Posting Whiz in Training

BMI = (wgt_kg/(hgt_m^2)) ; // BMI = kilograms/(meters^2)

This is in your function, but the variable is in main. You cannot use variables from main in the function. They are separate units and do not see the variables of the other unless they are passed to the function. You should do the calculation in your function and then return the result of the calculation to main. In main there should be a line like so:

BMI = BMIFunction(weight, height);

This line assigns the variable BMI the returning value of the function. You need to replace BMIFunction() with the proper name of the function, of course.

necrolin 94 Posting Whiz in Training
return 0 ;
}
#include <iostream>
using namespace std ;

int BMI(int weight, int height) ;
{

You don't need another #include .... using unless you put the function in another separate file. If they're together in one file then delete that.

Also, the declaration is:
int BMI(int weight, int height) ;

but the definition is:
int BMI(int weight, int height) {}

Notice that the definition has no semicolon at the end

necrolin 94 Posting Whiz in Training

Also, why did you give the function the same name as the variable? You need to give them different names.

necrolin 94 Posting Whiz in Training

Why are you using integers and multiplying them with numbers with a decimal point? You'll lose accuracy because everything after the decimal point will be cut from your integers. You'll get a more accurate calculation if you use doubles instead of integers throughout this work.

necrolin 94 Posting Whiz in Training

You have a few errors but I'll point you in the right direction.

1) As is you cannot use your function from main because it's defined after main but it wasn't declared before main ( so main doesn't see it). You can do one of two things to fix this:

a) Put your function at the top before main
b) Put a declaration at the top before main

int BMI(int weight, int height);

2) You are defining the function as int BMI(weight, height){} which is incorrect. What are "weight" and "height"? Are they int, double, string? You must place the correct type in there as I have shown under point 1.

3) It looks like you've got a couple of typos in there as well, but I'll let the compiler tell you where they are.

necrolin 94 Posting Whiz in Training

I think that the key to your problem is that "new" returns a "pointer". So, if you do this:

A a[];
a = new A[10];

Then if I'm reading it right then you are saying:
1) 'a' is an "array" of objects
2) 'a' is a "pointer" to an array of objects
A pointer is not exactly the same as an array and therefore you're getting the error.

However, if you say:

A* a;
a = new A[10];

then you are saying:
1) 'a' is a pointer
2) 'a' is a pointer to an array of objects
so technically it sounds correct and it works (compiles). Then any time you use pointers in an object you should take care of destruction, copying, and assignment to make sure that everything works right in your program, but you'll know best what you need because your needs will vary depending on how you plan to use the object.

I'm only on my first C++ course right now so that's the best explanation that I can give.

necrolin 94 Posting Whiz in Training

http://rpmfusion.org/

Actually your media player does support all the formats that are available, however, you need to install the codecs for non-free items like MP3. If you use the rpmfusion & livna repositories then you'll be able to install the non-free codecs to play anything from encrypted DVDs to all your music (and I believe they have VLC as well). All the instructions are on the website.

My only question is why are you using Fedora 7? If your computer can handle Windows 7 then why not use the latest Fedora 12? You'll have more updated software and most likely a much better user experience.

necrolin 94 Posting Whiz in Training

I still dont get it. This is what i have now im trying to input 1 2 3 4 5 6 7 and make that become row 1 instead of looping it countless times thanks;

To help you understand what you're doing let's go over your code:

Start a loop
      for (int j = 0; j < column; j++)
 
      {

      //Enter data into loop
      cout << "Please enter the numbers for the first row: ";
      cin >> myArray[j][i];
	  
      //You haven't changed the position of j yet so
      //overwrite what you just entered.... Ooops
	  cout<<"Please enter the numbers for the second row: ";
	  cin >> myArray[j][i];
	
      //Same as above, overwrite what you entered once again
	  cout <<"Please enter the numbers for the third row: ";
	  cin >> myArray[j][i];
	  

      }

You don't want to overwrite your data so you need to increment your counter every time you enter data.

//loop does nothing
     for (int i = 0; i < row; i++)

      {

     //loop does nothing
      for (int j = 0; j < column; j++)

      {

???

If you look at my post I clearly stated that you need TWO NESTED for loops like this:

//Increment the rows
    for (int i = 0; i < height; i++)
    {
        //Increment the columns
        //So for each ONE row this will execute for ALL your columns
        //So you're don't need any other loops except to output 
        //the data. This will fill your whole array... mind you that
        //your input statement isn't changing …
necrolin 94 Posting Whiz in Training

Here's an example. You'll still have to work your averages out.

#include <iostream>

using namespace std;

int main()
{
    const int height = 2;
    const int width = 4;

    int myArray[width][height];

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            cout << "Enter digit: ";
            cin >> myArray[j][i];
        }
    }

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            cout << myArray[j][i] << "  ";
        }
        cout << endl;
    }

}
necrolin 94 Posting Whiz in Training

You're not creating a 5x7 array. What you're doing is creating a 1x5 array. What you need is:

int myArray[5][7];

Then you'll need 2 nested for loops to assign the numbers to the array.

necrolin 94 Posting Whiz in Training

If you have an array and you delete it with the command: "delete array" then it still frees all of the memory because the memory was allocated in one big chunk. However, it does not call the destructors. Therefore, you want to use: "delete []array" instead which then tells it to delete an array and all the destructors get called.

necrolin 94 Posting Whiz in Training

If you're deleting an array then I believe the syntax is delete []myArray. Here's an example that compiles..

#include <iostream>

using namespace std;

class Object
{
public:
    Object() { cout << "Object::Object()\n"; }
    ~Object() { cout << "Object::~Object()\n"; }
};

int main()
{
    Object* o = new Object[5];
    delete []o;
}
necrolin 94 Posting Whiz in Training

YEah I thought that might be it.
is there any way to make those map_width and map_height variables into constants under the private: thing?

Thanks

Sure, you can have constants in a class like so:

static const int width = 100;

Or if you just want some numbers to put into the array you could also do something like this:

enum { width = 100 };

Both work fine.

necrolin 94 Posting Whiz in Training

It works just fine:

#include <iostream>

using std::cout;
using std::cin;

int main()
{
    bool again = true;

    do
    {
        cout << "Enter a digit between 0 & 1: ";
        int i;
        cin >> i;

        switch (i)
        {
            case (0):
               cout << "You chose 0\n";
               again = false;
               break;
            case (1):
                cout << "You chose 1\n";
                again = false;
                break;
            default:
              cout << "Wrong choice...\n";
        };
    } while (again);

    return 0;
}
necrolin 94 Posting Whiz in Training

I need to pass that data structures between multiple dll modules. So
there are initialization problems. So I can't use the std::vector :(.
But I think I can write my own wrapper class to encapsulate it if
C++ does not support this in the language level.

Correct me if I'm wrong, but couldn't you just....

#include <iostream>
#include <iomanip>

using std::cout;
using std::setw;

class A
{
	static int i;
public:
	A() { cout << setw(3) << i << ". A()\n"; i++; }
	~A() { i--; cout << setw(3) << i << ". ~A()\n"; }
};

int A::i = 1;

class B
{
	enum { sz = 10 };
	A* a;
public:
	B() { a = new A[sz]; }
	~B() { delete []a; }
};

int main()
{
	B b;
}

...do it like so? (Add your own copy constructors, and whatever else you might need)