Thread: Need some help..

  1. #1
    Registered User
    Join Date
    Nov 2001

    Need some help..

    Alright, I'm creating a program that's for a pay roll for school. I'm supposed to allow the teacher to view the payroll information and to edit it from another menu. Well, I've created a program that works except it won't take decimals, which I'm told is because I'm using char instead of int or double but when I try and use double or int and get rid of the atoi, I get an error. Here is one section of the program.

    /* 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 called
      ifstream mattb2 ("files/mattb2.txt");				//Opens the file mattb2.txt when mattb2 is called
      ifstream mattb3 ("files/mattb3.txt");				//Opens the file mattb3.txt when mattb3 is called
      if (! mattb.is_open())							//The IF statement that displays "error opening file" when file cannot be found
    	  cout << "Error opening file"; 
    		Sleep(1000);		//Sleep 1 second
      while (! mattb.eof() )							//Copies until the end of file (EOF)
        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);					//This stores the text of mattb3.txt as buffer3
    	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 seconds
      return 0;
    int mattbenter() 
      char a[5];
      char b[5];
      char c[5];
      int d;
      ofstream mattb ("files/mattb.txt");				//opens mattb.txt for editing
      ofstream mattb2 ("files/mattb2.txt");				//opens mattb2.txt for editing
      ofstream mattb3 ("files/mattb3.txt");				//opens mattb3.txt for editing
        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;
    	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 5 seconds
      if (mattb.is_open(), mattb2.is_open())
        mattb << a;
        mattb2 << b;
        mattb3 << d;
      return 0;
    /* End Matt B. Section */
    I thought this was C but apparently in my path to figure out how to create the program, I passed into C++ territory. Oh well.... Any suggestions?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    An annoying problem I'm sure. Fortunately, the fix is rather simple.
    Every time you wrote atoi, change it to atof. atoi will change a string into an integer, atof will change a string into a float value

    Be sure to assign the result to a double and not an int or you'll get warnings.

    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Thanx a lot. Yeah, deffinately annoying. I'll try it now

Popular pages Recent additions subscribe to a feed