huh wierd

This is a discussion on huh wierd within the C++ Programming forums, part of the General Programming Boards category; hello all I'm building a program and it seems I can't gets my while loop to work check it out ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    huh wierd

    hello all I'm building a program and it seems I can't gets my while loop to work check it out
    Code:
    #include<iostream>
    #include<string>
    #include<cmath>
    
    
    using namespace std;
    
    class point 
    
    { 
    private: int x ,y;
    public:
    //================================================================================================
    	void read()
    	{
    		cout<<"Enter a fraction: ";
    		cin>>x; cin.ignore(); cin>>y; 
    	}
    //================================================================================================
    	void show()
    	{
    	cout<<x<<"/"<<y;
    	}
    //================================================================================================
    friend point operator + (point p, point q)
    	{
    	point res;
    	res.x = (p.x * q.y) + (q.x * p.y);
    	res.y = (q.y * p.y);
    	return res;
    	}
    //================================================================================================
    friend point operator - (point p, point q) //operator overload for subtraction
    	{
    	point res;
    	res.x = (p.x * q.y) - (q.x * p.y);
    	res.y = (q.y * p.y);
    	return res;
    	}
    //================================================================================================
    friend point operator / (point p, point q)//operator overload for division
    	{
    	point res;
    	res.x = (p.x * q.y);
    	res.y = (p.y * q.x);
    	return res;
    	}
    };
    
    int main()
    {
    	point a , b;
    	char d;                              //variable d assigned for user input to cont. prog.
    	char e;								 //variable e assigned to decide type of operation
    while(d !='n')
    {
    	 cout<<"What kind operation would you like to perform:";
    	 cin>>e;							//user inputs variable e						
    //===============================================================================================	
    	switch(e)						//beginning of switch to decide which path of logic to use
    	{
    	case '+':
    		a.read();
    		b.read();
    
    		point r1 = a + b; 
    
    		a.show();
    		cout<<" + ";
    		b.show();
    		cout<<" = ";
    		
    		r1.show();
    	cout<<"\nWould you like to continue:Y/N? "; cin>>d;
    	
    	if(d ='n')
    		return 0;
    	break;
    //===============================================================================================	
    	case '-':
    
    		a.read();
    		b.read();
    
    		point r2 = a - b; 
    
    		a.show();
    		cout<<" - ";
    		b.show();
    		cout<<" = ";
    		
    		r2.show();
    		
    		cout<<"\nWould you like to continue:Y/N? "; cin>>d;
    		
    		
    	if(d='n')
    			return 0;
    	break;
    //================================================================================================	
    	case '/':
    	
    			a.read();
    		b.read();
    
    		point r3 = a / b; 
    
    		a.show();
    		cout<<char(246);
    		b.show();
    		cout<<" = ";
    		
    		r3.show();
    		
    		cout<<"\nWould you like to continue:Y/N? "; cin>>d;
    		
    		
    	if(d='n')
    			return 0;
    	break;
    
    
    		}
    
    	}
    		
    
    
    }
    any suggestions

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    char d;
    [...]
    while( d != 'n')


    what is 'd' to begin with? you didnt initialize it. it could have any value.

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Code:
    if(d ='n')
    should be
    Code:
    if(d =='n')

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    If these suggestions don't fully fix the problem, you might want to post some more specific information about what is going wrong with the loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Wierd **** - Order of Drawing Stuff?
    By Tonto in forum Game Programming
    Replies: 9
    Last Post: 11-09-2006, 08:56 PM
  2. Wierd chars...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-06-2006, 07:18 PM
  3. Wierd txt document
    By Necrofear in forum Tech Board
    Replies: 4
    Last Post: 05-22-2006, 09:24 PM
  4. make user press enter / wierd code thingy
    By CorvusVita in forum C++ Programming
    Replies: 10
    Last Post: 04-05-2006, 09:55 AM
  5. When to say when, huh?
    By correlcj in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-17-2002, 08:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21