Thread: could I get a bit more help

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    could I get a bit more help

    Hello, I keep getting this error

    Run-Time Check Failure #2 – Stack around the variable ‘wage’ was corrupted

    anyone able to point me in the right direction please?

    Code:
    #include <iostream>
    #include <iomanip>
    #include <C:\Documents and Settings\Pat\Desktop\school\prog14.cpp\prog14.cpp\empinfo.h.cpp>
    
    using namespace std;
    
    int main()
    {
    	const int MAX = 25;
    	struct info employee[MAX];
    	int count = 1;
    	char (ret);
    
    	for (int i=0; i<=count; i++)
    	{
    		cout << "input Last Name:"<< endl;
    		cin.getline (employee[i].last1,25);
    		cout << "Input First Name:" << endl;
    		cin.getline (employee[i].first1,25);
    		cout << "Input payrate:" << endl;
    		cin >> employee[i].payrate;
    		cout << "Input Hours Worked:" << endl;
    		cin >> employee[i].hours;
    		cin.get (ret);
    	}
    double wage[1];
    
    for (int j=0; j<=count; j++)
    {
    	
    if (employee[j].hours <=40)
    	wage[j] = employee[j].payrate *40;
    else  wage[j] =employee[j].payrate*40 +(employee[j].hours - 40) * employee[j].payrate * (3/2);
    
    cout << employee[j].last1 << setw(10) << employee[j].first1 << endl;
    cout << employee[j].payrate << endl;
    cout << employee[j].hours << endl;
    }
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    my struct info

    Code:
    struct info
    	{
    		char last1 [25];
    		char first1 [25];
    		double payrate;
    		int hours;
    	
    	};

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    you might want to work on your indenting, it's kinda hard to read like that

    Code:
    for (int j=0; j<=count; j++)
    that goes outside of the wage array

    Code:
    double wage[1];
    you're planning on adding more right?

    either change count to 2 or replace wage[1] by wage[any number higher than 1]
    Last edited by h_howee; 11-28-2006 at 10:26 PM.

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Or to be more precise, I think you want
    Code:
    double wage[MAX];
    Edit: Also, if count is the number of employees, the loop conditions should be i<count and j<count, not i<=count and j<=count.
    Last edited by robatino; 11-28-2006 at 10:27 PM.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    Talking thanks

    thank you very much that did it

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I told you that in your other thread.
    http://cboard.cprogramming.com/showp...03&postcount=3
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bit manipulation
    By Neo1 in forum C++ Programming
    Replies: 8
    Last Post: 03-24-2008, 11:53 AM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  4. Bitwise Operators - Setting and Retreiving a Bit
    By Spono in forum C Programming
    Replies: 2
    Last Post: 11-04-2003, 02:09 PM
  5. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 02:17 PM