Results 1 to 4 of 4

Thread: wahts wrong here? simple application compiles, not right output

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    wahts wrong here? simple application compiles, not right output

    Hello everyone, with this sipmle program it puts out the right output, but i get an illegal operation when i type in 0, then i convert 0 to feherinheite, it prints out the rgiht result(32) but it says an illegal operation has occured here is teh illegal operation:
    Code:
    CONVERTER caused an invalid page fault in
    module CONVERTER.EXE at 0187:0042684c.
    Registers:
    EAX=00000000 CS=0187 EIP=0042684c EFLGS=00010206
    EBX=005b0000 SS=018f ESP=006bfe0c EBP=40400000
    ECX=006bfe28 DS=018f ESI=8829fcc4 FS=9d2f
    EDX=0047b804 ES=018f EDI=00000000 GS=0000
    Bytes at CS:EIP:
    89 45 e4 8b 55 e4 52 e8 78 fd ff ff 8b 45 ec 8b 
    Stack dump:
    00000000 8829fcc4 005b0000 c0000005 006bff68 006bfe0c 006bfc3c 006bff68 0043069c 004711d0 00000000 006bff78 bff8b560 00000000 8829fcc4 005b0000
    here is my code:
    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    
    int main()
    {
    	const int MAX = 40;
    	double fah[MAX];
    	double cel[MAX];
    	char buff[MAX];
    	int choice;
    	double degree;
    
    	cout <<"Enter a number: \n";
    	cin.get(buff,MAX); cin.ignore(200,'\n');
    
    	if(strcmp(buff,"end") == 0)
    	{
    		cout <<"Thank you for using the program.";
    	}
    	else
    	{
    		degree = atof(buff);
    		
    		cout <<"(1) to convert celsius to fahrenheit\n";
    		cout <<"(2) to convert fahrenheit to celsius" << endl;
    		
    		cin >> choice;
    
    		switch(choice)
    		{
    		case 1: fah[MAX] = (((degree + 40) * 1.8) - 40);
    			cout << fah[MAX] << endl;
    			break;
    		case 2: cel[MAX] = ((degree -32) / 1.8);
    			cout << cel[MAX] << endl;
    			break;
    		default: cout <<"error occured.\n";
    			break;
    		}
    	
    		cout <<"thank you for using this application\n";
    	}
    
    	return 0;
    }

    thanks for listening

  2. #2
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    ummm, why exactly do u use an array??

    I'd say its probably a stack overflow,,,,

    Wait a minute!!

    Never assign anything to the array[MAX] because that is technically invalid since tha array starts at 0.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    screw the arrays, and use double fah,cel;
    cout can handle double's
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Yes exactly, I dont see any for loops.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width