Thread: Problem with program...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    15

    Problem with program...

    Here's an example of part of a program I'm working on. I'm trying to get the program to do the correct math with the hours, overtime, and bonus enter (to see what I mean, take a look at the code below).
    EXAMPLE:
    Code:
    d = atoi(c) * 15;
    The program does not accept any decimal numbers and will not allow me to multiply the hours by a decimal. Anyone have any ideas? I'd greatly appreciate it.

    Code:
    /* Begin Matt B. Section */
    int mattbview()
    {
      char buffer[256];
      char buffer2[256];
      char buffer3[256];
      int ammount;
      ifstream mattb ("files/mattb.txt");				//Opens the file mattb.txt when mattb is typed
      ifstream mattb2 ("files/mattb2.txt");				//Opens the file mattb2.txt when mattb2 is typed
      ifstream mattb3 ("files/mattb3.txt");
      if (! mattb.is_open())							//The IF statement that displays "error opening file" when file cannot be found
      { 
    	  cout << "Error opening file"; 
    	  EXIT 
    		Sleep(1000);		//Sleep 1 second
      }
    
      while (! mattb.eof() )							//Copies until the end of file (EOF)
      {
    	system("CLS");
        mattb.getline (buffer,100);						//This stores the text of mattb.txt as buffer
    	mattb2.getline (buffer2,100);					//This stores the text of mattb2.txt as buffer2
    	mattb3.getline (buffer3,100);
    	cout << endl << "\tName:  Matt Biltcliffe";
    	cout << endl << "\tRate:  $10/hour";
    	cout << endl << "\tMatt has worked "; 
        cout << buffer;
    	cout << " hours.";
    	cout << endl << "\tMatt has recieved a bonus of $";
    	cout << buffer2;
    	cout << " this week.";
    	ammount = atoi(buffer) * 10 + atoi(buffer2) + atoi(buffer3);	//The math involved to figure out total money
    	cout << endl << "\tThe total ammount of money owed to Matt is $";
    	cout << ammount;
    	cout << ".";
    	cout << endl << endl << endl;
    	Sleep(5000);		//Sleep 5 second
    	
      }
      main();
      return 0;
    }
    int mattbenter() 
    {
      char a[5];
      char b[5];
      char c[5];
      int d;
      ofstream mattb ("files/mattb.txt");
      ofstream mattb2 ("files/mattb2.txt");
      ofstream mattb3 ("files/mattb3.txt");
        cout << endl << "\tName:  Matt Biltcliffe";
    	cout << endl << "\tPay:  $10/hour";
    	cout << endl << "\tPlease note that ONLY numbers are allowed.";
    	cout << endl << endl << "\tPlease enter the ammount of hours worked (Standard pay):  ";
    	cin >> a;
    	cout << "\tPlease enter the amount of overtime worked (Time and a half):  ";
    	cin >> c;
    	cout << "\tPlease enter the bonus you'd like to give the employee:  ";
    	cin >> b;
    	mattbview();
      }
    
    	cout << endl << "\tThank you, this is being entered into the database now and Matt's pay is being calculated.";
    	cout << endl;
    	d = atoi(c) * 15;
    	Sleep(5000);		//Sleep 1 second
      if (mattb.is_open(), mattb2.is_open())
      {
        mattb << a;
        mattb2 << b;
        mattb3 << d;
    	mattb.close();
    	mattb2.close();
    	mattb3.close();  return 0;
    }
    BTW: Sorry about all my problems with my pay roll project. Just been havin trouble with a few things. For the most part, the program works as long as there isn't any decimals to be entered.
    Last edited by Screwz Luse; 12-05-2001 at 09:50 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This is not the C++ board. Post there, unless you have already, in which case, stop cross posting here!
    cout << endl << "\tName: Matt Biltcliffe";
    cout << endl << "\tRate: $10/hour";
    cout << endl << "\tMatt has worked ";
    Um... 'matt has worked' ? ...ok, so what? Is there supposed to be a variable at the end there? (Don't reply here, go to the C++ board.)

    cin >> a;
    cout << "\tPlease enter the amount of overtime worked (Time and a half): ";
    cin >> c;
    cout << "\tPlease enter the bonus you'd like to give the employee: ";
    cin >> b;
    'a', 'b', and 'c' are not declared anywhere in the code you provide.

    I suspect the reason your multiplication isn't working is because you aren't properly declaring your variables. If you want a decimal, use a float or double, not an integer.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    15
    well, excuse me. No need to get all ........y and snooty about it. I'm sorry if I've hurt you, all knowing one. 1.) My bad, I didn't really think that I had carried over to C++ really 2.) a, b, and c are defined:

    Code:
    char a[5];  
    char b[5];  
    char c[5];
    If you had looked at the code, you would see that a variable comes after the "matt's work" part.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I wasn't being ........y. I was letting you know that there is a board for C++, and that this isn't it.

    Ya, I glanced over the code, totally missed the 'abc' stuff. My bad.

    Where isn't it excepting the decimal input? Into abc? Shouldn't those be a float or a double? With 'cin', you should be just reading into a float or double, not into an array of characters. That should do the trick.

    Quzah.
    Last edited by quzah; 12-05-2001 at 11:29 AM.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    15
    lol.. thanx. Sorry about the "rudeness" in my reply. My bad.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 11:10 AM
  2. Program Termination Problem
    By dacbo in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 02:34 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  4. Replies: 20
    Last Post: 06-12-2005, 11:53 PM