floating point error in C++
-
I wrote this code for a school project,since i use vista and dos doesn't work properly on it ,i normally use the emulator DOSBOX.The problem is this program runs well on DOSBOX but not on the normal DOS platform. It gives an error
Floating point error:domain Abnormal program termination
Here's the code,its on text file encryption.My school requires me to use the ancient "turbo c++ 3.0"#include
#include
#include
#include
#includeint strtoken(char k[]) {
int N = strlen(k);
int sum = 0 ;for (int q=0;q\>choice;
if(choice==3) {
clrscr();cout<<" Instructions \n ------------- \n\n\n 1.Choose whether to encrypt or decrypt a file ";
cout<<"\n 2.Enter the input and output filenames (if the file is in same directory as texcrypt ,if not,then enter the full path of the file)";
cout<<"\n 3.Enter the key to encrypt/decrypt the file with(your file will be encrypted on the basis of the key entered).";
cout<<"\n 4.The output file will be your encrypted/decrypted file";
cout<<"\n\n\n\nPress any key to return ...... ";getch();
goto start;
}
else if(choice==4)
return 0;
char text[3][20] = {"","encrypted","decrypted"};clrscr(); cout<<"Enter input filename : "; gets(ifname); fflush(stdin); cout<<"\\n"; int i; ifstream infile(""); ofstream outfile(""); infile.open(ifname); if(!infile) { // if file is not found cout<<"Error:File not found"; goto end; } cout<<"Enter output filename : ";g
-
I wrote this code for a school project,since i use vista and dos doesn't work properly on it ,i normally use the emulator DOSBOX.The problem is this program runs well on DOSBOX but not on the normal DOS platform. It gives an error
Floating point error:domain Abnormal program termination
Here's the code,its on text file encryption.My school requires me to use the ancient "turbo c++ 3.0"#include
#include
#include
#include
#includeint strtoken(char k[]) {
int N = strlen(k);
int sum = 0 ;for (int q=0;q\>choice;
if(choice==3) {
clrscr();cout<<" Instructions \n ------------- \n\n\n 1.Choose whether to encrypt or decrypt a file ";
cout<<"\n 2.Enter the input and output filenames (if the file is in same directory as texcrypt ,if not,then enter the full path of the file)";
cout<<"\n 3.Enter the key to encrypt/decrypt the file with(your file will be encrypted on the basis of the key entered).";
cout<<"\n 4.The output file will be your encrypted/decrypted file";
cout<<"\n\n\n\nPress any key to return ...... ";getch();
goto start;
}
else if(choice==4)
return 0;
char text[3][20] = {"","encrypted","decrypted"};clrscr(); cout<<"Enter input filename : "; gets(ifname); fflush(stdin); cout<<"\\n"; int i; ifstream infile(""); ofstream outfile(""); infile.open(ifname); if(!infile) { // if file is not found cout<<"Error:File not found"; goto end; } cout<<"Enter output filename : ";g
Hint: narrow the problem down to just small handful of relevant lines. No one wants to wade through all of this when you could do most of it yourself.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Hint: narrow the problem down to just small handful of relevant lines. No one wants to wade through all of this when you could do most of it yourself.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
sorry about that,here is where i think the problem is
cout<<"Enter input filename : "; gets(ifname); fflush(stdin); cout<<"\\n"; int i; ifstream infile(""); ofstream outfile(""); infile.open(ifname); cout<<"Enter output filename : ";gets(ofname);fflush(stdin); cout<<"\\n"; outfile.open(ofname);
second place ---------------
cout<<"Enter key: ";
for(i=0;;i++) { Key\[i\]=getch(); if (Key\[i\] == '\\r') break; cout<<"\*"; } Key\[i\] = '\\0'; int token= strtoken(Key); int token2= strtoken2(Key); fflush(stdin); cout<<"\\n"; while (infile) { while(infile){ infile.get(ch); if(!infile){ cout<<"\\nThe file was successfully encrypted."; getch(); goto end; } ch=char((ch+token-(token2))%255); outfile.put(ch); } }
-
I wrote this code for a school project,since i use vista and dos doesn't work properly on it ,i normally use the emulator DOSBOX.The problem is this program runs well on DOSBOX but not on the normal DOS platform. It gives an error
Floating point error:domain Abnormal program termination
Here's the code,its on text file encryption.My school requires me to use the ancient "turbo c++ 3.0"#include
#include
#include
#include
#includeint strtoken(char k[]) {
int N = strlen(k);
int sum = 0 ;for (int q=0;q\>choice;
if(choice==3) {
clrscr();cout<<" Instructions \n ------------- \n\n\n 1.Choose whether to encrypt or decrypt a file ";
cout<<"\n 2.Enter the input and output filenames (if the file is in same directory as texcrypt ,if not,then enter the full path of the file)";
cout<<"\n 3.Enter the key to encrypt/decrypt the file with(your file will be encrypted on the basis of the key entered).";
cout<<"\n 4.The output file will be your encrypted/decrypted file";
cout<<"\n\n\n\nPress any key to return ...... ";getch();
goto start;
}
else if(choice==4)
return 0;
char text[3][20] = {"","encrypted","decrypted"};clrscr(); cout<<"Enter input filename : "; gets(ifname); fflush(stdin); cout<<"\\n"; int i; ifstream infile(""); ofstream outfile(""); infile.open(ifname); if(!infile) { // if file is not found cout<<"Error:File not found"; goto end; } cout<<"Enter output filename : ";g
Vivek Narayanan wrote:
t=pow(2,t);
I suspect your problem has to do with this statement. Change it to:
t = pow(2.0, t);
Since this is a C++ project, why are you using
char
instead ofstring
?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
I wrote this code for a school project,since i use vista and dos doesn't work properly on it ,i normally use the emulator DOSBOX.The problem is this program runs well on DOSBOX but not on the normal DOS platform. It gives an error
Floating point error:domain Abnormal program termination
Here's the code,its on text file encryption.My school requires me to use the ancient "turbo c++ 3.0"#include
#include
#include
#include
#includeint strtoken(char k[]) {
int N = strlen(k);
int sum = 0 ;for (int q=0;q\>choice;
if(choice==3) {
clrscr();cout<<" Instructions \n ------------- \n\n\n 1.Choose whether to encrypt or decrypt a file ";
cout<<"\n 2.Enter the input and output filenames (if the file is in same directory as texcrypt ,if not,then enter the full path of the file)";
cout<<"\n 3.Enter the key to encrypt/decrypt the file with(your file will be encrypted on the basis of the key entered).";
cout<<"\n 4.The output file will be your encrypted/decrypted file";
cout<<"\n\n\n\nPress any key to return ...... ";getch();
goto start;
}
else if(choice==4)
return 0;
char text[3][20] = {"","encrypted","decrypted"};clrscr(); cout<<"Enter input filename : "; gets(ifname); fflush(stdin); cout<<"\\n"; int i; ifstream infile(""); ofstream outfile(""); infile.open(ifname); if(!infile) { // if file is not found cout<<"Error:File not found"; goto end; } cout<<"Enter output filename : ";g
A good technique to learn early in one's career in programming is this: when you have a problem where you don't have any idea where the problem lies, comment out sections, placing hard coded (good) values where necessary and see if the unexplained problem goes away. This is a good place to start when you don't know where else to start.
-
Vivek Narayanan wrote:
t=pow(2,t);
I suspect your problem has to do with this statement. Change it to:
t = pow(2.0, t);
Since this is a C++ project, why are you using
char
instead ofstring
?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
i tried that,it didn't solve the problem,it works in the emulator DOSBOX but not on the real DOS platform,could this be some sort of memory problem?