Thread: What The Heck Is Wrong W/ This?

  1. #1
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25

    What The Heck Is Wrong W/ This?

    hello, i am a basic person so i created a basic program
    it says some error that doesnt any sense.....I posted it

    if you can spare the time to overveiw my code i would reallt appretiate it
    ---------------------------------------------------------------------------
    This program askes u if u want to divide multiply add subtract square numbers... i tryed to put in a loop but thats what got everything messed up
    ---------------------------------------------------------------------------
    fatal error C1004: unexpected end of file found
    ---------------------------------------------------------------------------
    Code:
    /*********************************************
    **********************************************
    **********************************************
    *************** Brett Charles ****************
    ************ [email protected] ***********
    ********* Cprograming.com membership: ********
    ****************** Prodigy *******************
    **********************************************
    **********************************************
    **********************************************/
    
    #include <iostream.h>
    #include <stdlib.h>
    int main ()
    {
    	char c;
    	int x,y,z;
    	bool active = true;
    	char response;
    	while(active)
    	{
    	cout << "				-------" << endl;
    	cout << "				Welcome" << endl;
    	cout << "				-------" << endl;
    	cout << "Push q if u would like to square, d to divide, s to subtract, a to add, and m to multiply"<< endl;
    	cin >> c;
    	if((c == 'q')||(c == 'Q'))
    	{
    		cout << "				------" ;
    		cout << "\n				Square";
    		cout << "\n				------";
    
    		cout << "\nEnter a number: ";
    		cin >> x;
    		y = x * x;
    		cout << x << " squared = "<< y << endl;
    	}
    	if ((c == 'd')||(c == 'D'))
    	{
    		cout << "				------";
    		cout << "\n				Divide";
    		cout << "\n				------";
    		cout << "\nEnter a dividend: ";
    		cin >> x;
    		cout << "\nType in a divisor: ";
    		cin >> y;
    		z = x/y;
    		cout << x << " / " << y << " = " << z << endl;
    	if (x == y)
    	cout << "\aError cannot divide by zero!!!" << endl;
    	}
    	if ((c == 's')||(c == 'S'))
    	{
    		cout << "				--------";
    		cout << "\n				Subtract";
    		cout << "\n				--------";
    		cout << "\nType in a number: ";
    		cin >> x;
    		cout << "\nType in anoher number: ";
    		cin >> y;
    		z = x - y;
    		cout << x << " - " << y << " = " << z << endl;
    	}
    	if ((c == 'a')||(c == 'A'))
    	{
    		cout << "				---";
    		cout << "\n				Add";
    		cout << "\n				---";
    		
    		
    		cout << "Type in a number: ";
    		cin >> x;
    		cout << "Type in another number: ";
    		cin >> y;
    		z = x + y;
    		cout << x << " + " << y << " = " << z << endl;
    	}
    	if ((c == 'm')||(c == 'M'))
    	{
    		cout << "				--------";
    		cout << "\n				Multiply";
    		cout << "\n				--------";
    		cout << "Type in a number: ";
    		cin >> x;
    		cout << "Type in another number: ";
    		cin >> y;
    		z = x * y;
    		cout << x << " * " << y << " = " << z << endl;
    	}
    	cout<<endl<<"Again? Y / N"<<endl;
    	cin>>response;
    
    	switch(response)
    	{
    	case 'y':
    		{
    		}break;
    	case 'Y':
    		{
    		}break;
    	case 'n':
    		{
    			active = false;
    		}break;
    	case 'N':
    		{
    			active = false;
    		}break;
    return 0;
    	}
    //right here it says the error is
    
    // fatal error C1004: unexpected end of file found
    
    
    //	I DONT KNOW WHATS WRONG!!!!!!!!!!!!!!!!!!
    Last edited by Prodigy; 05-05-2002 at 08:45 AM.
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:[email protected]
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    If you had idented your code, you would see that something missed:

    Code:
    switch(response) 
    { 
        case 'y': 
        { 
        }break; 
         case 'Y': 
        { 
        }break; 
        case 'n': 
        { 
        active = false; 
        }break; 
        case 'N': 
        { 
        active = false; 
        }break; 
    }
    You can use code tags with

    [ code ]
    // your code
    [ /code ]

    Note that the spaces must be left away, I just added them because else it would be converted to tags and you wouldn't see how to do it.

  3. #3
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25
    thx

    but i dont see what i missed
    Last edited by Prodigy; 05-05-2002 at 08:52 AM.
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:[email protected]
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    You missed the last } to close the switch-construction. Also you could consider to close the switch-cases with default.

    Code:
    switch (condition)
    {
        ...
        default:
            break;
    } <- you missed that thing

  5. #5
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25
    i did that but sad same error
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:[email protected]
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  6. #6
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25
    Originally posted by Prodigy
    i did that but sad same error
    oos forget it there was another 1 i missed thx
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:[email protected]
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    95
    Code:
    if ((c == 'd')||(c == 'D'))
    	{
    		cout << "				------";
    		cout << "\n				Divide";
    		cout << "\n				------";
    		cout << "\nEnter a dividend: ";
    		cin >> x;
    		cout << "\nType in a divisor: ";
    		cin >> y;
    		z = x/y;
    		cout << x << " / " << y << " = " << z << endl;
    	if (x == y)
    	cout << "\aError cannot divide by zero!!!" << endl;
    	}
    is this a logic error?
    z=x/y
    you devide before validating y to make sure it isn't 0
    shouldn't you place your if statement first and make it y==0?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  2. What the heck is wrong with my database?
    By Blizzarddog in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 10:51 AM
  3. What the heck is wrong with this code?
    By Shadow12345 in forum C++ Programming
    Replies: 4
    Last Post: 09-25-2002, 02:58 PM
  4. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM
  5. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 08:14 AM