Thread: why won't this program finish?

  1. #1
    Registered User brianptodd's Avatar
    Join Date
    Oct 2002
    Posts
    66

    why won't this program finish?

    My program compiles, and runs correctly, except at the end. It gets stuck and I have to ctrl+break to end it...Anybody know why?

    Here is the code:

    Code:
    #include <iostream>
     #include <string>
     #include "employee.h"
     #include "employee.cpp"
     #include "myfuncts.h"
     #include "myfuncts.cpp"
    
     template <class Type>
     Type largest(Type obj1, Type obj2, Type obj3);
    
     template <class Type>
    Type prints3(Type obj1, Type obj2, Type obj3);
    
    
     int main()
     {
    	 //	character input
    	 char a, b, c;
    	 cout << "Enter three single characters separated by a space: ";
    	 cin >> a >> b >> c;
    	 prints3(a, b, c);
    	 largest(a, b, c);
    
    	 //	integer input
    	 int one, two, three;
    	 cout << "Enter three integers separated by a space: ";
    	 cin >> one >> two >> three;
    	 prints3(one, two, three);
    	 largest(one, two, three);
    
    	 //	float input
    	 float four, five, six;
    	 cout << "Enter three floating point numbers separated by a space: ";
    	 cin >> four >> five >> six;
    	 prints3(four, five, six);
    	 largest(four, five, six);
    
    	 //	double input
    	 double seven, eight, nine;
    	 cout << "Enter three doubles separated by a space: ";
    	 cin >> seven >> eight >> nine;
    	 prints3(seven, eight, nine);
    	 largest(seven, eight, nine);
    
    	 //	string input
    	 string str1, str2, str3;
    	 cout << "Enter three strings separated by a space: ";
    	 cin >> str1 >> str2 >> str3;
    	 prints3(str1, str2, str3);
    	 largest(str1, str2, str3);
    
    	 //	Employee input
    	 double sal1, sal2, sal3;
    	 Employee emp1("Donald Duck", 0);
    	 Employee emp2("Little Bo Peep", 0);
    	 Employee emp3("Jack Horner", 0);
    	 cout << "Enter three employee salaries separated by a space: ";
    	 cin >> sal1 >> sal2 >> sal3;
    
    	 emp1.set_salary(sal1);
    	 emp2.set_salary(sal2);
    	 emp3.set_salary(sal3);
    
    	 prints3(sal1, sal2, sal3);
    	 largest(sal1, sal2, sal3);
    
    	 int p1, q1, r1, *p, *q, *r;
    	 cout << "Enter three integers separated by a space: ";
    	 cin >> p1 >> q1 >> r1;
    	 p = &p1;
    	 q = &q1;
    	 r = &r1;
    	 prints3(*p, *q, *r);
    	 largest(*p, *q, *r);
    
    
    
    
    
    	 return 0;
    }
    
    
    
    template <class Type>
    Type prints3(Type obj1, Type obj2, Type obj3)
    {
    	cout << "You entered " << obj1 << " and " << obj2 << " and " << obj3 << endl;
    
    }
    
    template <class Type>
    Type largest(Type obj1, Type obj2, Type obj3)
    {
       Type largest;
       if(obj1 >= obj2 && obj1 >= obj3)
       {
    	   largest = obj1;
    	}
    	else if (obj2 >= obj1 && obj2 >= obj3)
    	{
    		largest = obj2;
    	}
    	else
    	largest = obj3;
    
        cout << "Largest: " << largest << endl;
    
    }
    Thanks,

    Brian
    "In theory, there is no difference between theory and practice. But, in practice, there is."
    - Jan L.A. van de Snepscheut

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    I am looking at your code. I edit my original post becuase it was incorrect. I will post again when I have something for you.
    Last edited by bonkey; 12-02-2002 at 10:33 AM.
    Best Regards,

    Bonkey

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    It works for me, I had to change the return type from Type to void, since your functions do not return a value. Once I did that, it compiled ran and completed fine.
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Replies: 40
    Last Post: 09-01-2006, 12:09 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM