ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have a problem, and I wondered if someone here has a solution. I wrote a program in C++. It compiles OK with the g++ compiler - no errors or warnings. It runs okay on Windows XP. In my SuSE Linux Gnome terminal however, I get the following output:
jp@localhost:~/C++> g++ /home/jp/C++/Kalculus0.0.0.6.cpp -o Kalculus
jp@localhost:~/C++> ./Kalculus
Welcome to Kalculator version 0.0
Type help() for help.
Type quit() to quit the program.
jp@localhost:~/C++>
So it runs the first few lines of the code, and as soon as the user has to give some input, it returns to the Shell. Someone who knows why?
I have a problem, and I wondered if someone here has a solution. I wrote a program in C++. It compiles OK with the g++ compiler - no errors or warnings. It runs okay on Windows XP. In my SuSE Linux Gnome terminal however, I get the following output:
jp@localhost:~/C++> g++ /home/jp/C++/Kalculus0.0.0.6.cpp -o Kalculus
jp@localhost:~/C++> ./Kalculus
Welcome to Kalculator version 0.0
Type help() for help.
Type quit() to quit the program.
jp@localhost:~/C++>
So it runs the first few lines of the code, and as soon as the user has to give some input, it returns to the Shell. Someone who knows why?
Sorry; here the code is. It is a calculator, so I left out the functions and the variable declarations; methinks they're not very interesting now. The function calculate() does the actual math(it still has to be written), and the help() function is supposed to give some information on the functions. However, the program does not even get to them, it seems, so I left them out. The code:
Code:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include </gsl/cdf/gsl_cdf.h>
using namespace std;
int main()
{
cout<<"Welcome to Kalculus version 0.0\n"
<<"Type help for help.\n"
<<"Type quit to quit the program.\n\n";
while (bool_terminate == 0)
{
bool_processed = 0;
getline(cin, str_command, '\n');
if (str_command == "quit()" || str_command == "quit")
{
bool_processed = 1;
bool_terminate = 1;
}
str_test = str_command.substr(0,4);
if (str_test == "help")
{
bool_processed = 1;
str_command = str_command.erase(0,4);
help(str_command);
}
if (bool_processed == 0)
{
calculate(str_command);
}
if (bool_processed == 0 && str_command != "")
{
cout<<"'"<< str_command <<"' has an incorrect syntax.\n"
<<"Type 'help()' for more information on functions and their syntaxes.\n";
}
}
}
Surely you need bool_terminate to be defined before the while loop. I'm surprised that compiles and doesn't complain about that variable not being defined before being used.
Where ever it is you declare bool_teminate you need to initialize it with 0. In fact, you should make sure you initalize ALL non-user defined typed variables.
The problem is, when this while loop starts, we don't know what bool_terminate is set to unless we've initialized it to something. If you really wanted to find out what it is set to, do a cout << string (bool_terminate? "True", "False") << endl; right before the loop.
/tmp/ccbegiBG.o: In function `func_InvNorm(double, double, double)':
Kalculus0.0.0.7.cpp.text+0x14cc): undefined reference to `gsl_cdf_gaussian_Pinv'
/tmp/ccbegiBG.o: In function `func_normalcdf(double, double, double)':
Kalculus0.0.0.7.cpp.text+0x150e): undefined reference to `gsl_cdf_gaussian_P'
collect2: ld returned 1 exit status
What does that mean?
Thanks!
Yours, Alkibiades
Last edited by Alkibiades; 10-26-2006 at 03:56 PM.
>Thank you very much, Mjones490 and Nylex, you were right; defining bool_terminate helps.
so it was compiling without having bool_terminate declared?
No, it was compiling with a declared bool_terminate, but as bool_terminate was undefined, the loop stopped looping immediately and thence the program was terminated.
No, it was compiling with a declared bool_terminate, but as bool_terminate was undefined, the loop stopped looping immediately and thence the program was terminated.
yeh. where was it declared at? is it declared in gsl_cdf.h ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.