Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. floating point error in C++

floating point error in C++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++security
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vivek Narayanan
    wrote on last edited by
    #1

    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
    #include

    int 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
    
    D K 3 Replies Last reply
    0
    • V Vivek Narayanan

      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
      #include

      int 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
      
      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • D David Crow

        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

        V Offline
        V Offline
        Vivek Narayanan
        wrote on last edited by
        #3

        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);
        				   }
        				   }
        
        1 Reply Last reply
        0
        • V Vivek Narayanan

          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
          #include

          int 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
          
          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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 of string?

          "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

          V 1 Reply Last reply
          0
          • V Vivek Narayanan

            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
            #include

            int 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
            
            K Offline
            K Offline
            Koolski
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • D David Crow

              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 of string?

              "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

              V Offline
              V Offline
              Vivek Narayanan
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups