Thread: can't get this program to run correctly

  1. #1
    UpTooLate
    Join Date
    Feb 2008
    Location
    New York
    Posts
    32

    Talking can't get this program to run correctly

    Okay so here is what the program is supposed to do:

    “This program estimates the social security deduction (for an
    imaginary country) where people who earn less than $1,500 a week
    pay a certain rate (.136) , people who earn $1,500 or more, pay the same
    rate up to $1,500 and then pay a lower rate (.056) on the additional
    income they've earned.

    The program will prompt a user for an hourly wage and whether or not the user
    works a standard 40 hours a week (as a y/n question).
    If the user indicates that he or she works a different number of hours,
    they should be promted for how many hours they work

    The program then will output the total weekly wage and
    the amount of social security deducted.


    This is the actual program I have written and I can’t figure out what I am doing wrong:
    The program first asks the user to “Enter your hourly wages.” (this is what it is supposed to do)
    Then you type an amount in and then it asks “Do you work a standard 40 hour week?”
    BUT THEN it asks to press any key to continue and it closes the program!!
    Can anyone give me some tips?? I have been at this for about 5 hours now! Here it is:



    Code:
     
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        
        cout<< "Enter your hourly wages: ";
        double hourlywage;
        cin>> hourlywage;
        cout << "Do you work a standard 40 hour week? (Y/N): " ;
        char Answer;
        cin>> Answer;
        double SocialSecurity;
        double weeklywages;
        
        if ( Answer == 'Y')
    {   
     ((40 * hourlywage) == weeklywages) ;
        	(( weeklywages * .136 ) == SocialSecurity) ;    
         cout<< "Your weekly wages total "<< weeklywages << "." <<endl; 
        cout<< "The total amount of Social Security deducted is " << SocialSecurity << "."<< endl;    
    }
    
        else if (Answer = 'N'    
    {
             cout<< "How many hours do you work per week?" ;         
     	double hoursweekly; 
             cin>> hoursweekly; 
             double weeklywages2; 
             (( hourlywage * hoursweekly) = weeklywages2) ;
             
    if (weeklywages2 < 1500) // if their weekly wages are LESS THAN 1500
    { 
    ((weeklywages2 * .136) == SocialSecurity) ;
    cout<<"Your weekly wages total "<< weeklywages2 <<"."<<endl;            cout<<"The total amount of Social Security deducted is " << SocialSecurity << "."<<endl;            
    }
             else if (weeklywages2 >= 1500         
    {
                  double amountover; 
                  double SocialSecurity1; 
                  double SocialSecurity2; 
                  double TotalSS; 
                  (( weeklywages2 - 1500) = amountover) ;              
    (( 1500 * .136 ) == SocialSecurity1) ;              
    (( amountover * .056 ) = SocialSecurity2) ; 
    (( SocialSecurity1 + SocialSecurity2 ) = TotalSS);              
    cout <<"Your weekly wages total " << weeklywages2 << "." << endl;              
    
    cout <<"The total amount of Social Security deducted is " << TotalSS << "."<< endl;          }
             
             system("pause");
             return 0;
    }}

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The line
    Code:
    cin>> Answer;
    only reads in one character, so it leaves the "enter" key waiting around for the next time you call input. Try adding cin.ignore(); before reading the next number.

    Edit: I got that backwards -- cin is reading the enter key into Answer (from the last time), so put a cin.ignore() here and see if that helps.
    Last edited by tabstop; 02-05-2008 at 04:04 PM.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Your bracket is in the wrong place. It should be;

    Code:
        
    
     }
         cin.get();
             return 0;
    }
    Btw, you're missing closing brackets for certain arguments.

    Code:
     else if (weeklywages>2= 1500
    Last edited by Oldman47; 02-05-2008 at 04:05 PM.

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Also, what is this?
    Code:
    ((40 * hourlywage) == weeklywages) ;
    (( weeklywages * .136 ) == SocialSecurity) ;
    Presumably you mean
    Code:
    weeklywages = 40 * hourlywage;
    SocialSecurity = weeklywages * .136 = SocialSecurity

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Getting a C# program with a manifest file to run in the debugger
    By Xarzu Athanasop in forum C# Programming
    Replies: 0
    Last Post: 01-18-2008, 06:34 PM
  4. Re-doing a C program to run in Win2000 or XP
    By fifi in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 05:32 PM
  5. Run A Program from within a cpp code
    By Hexxx in forum C++ Programming
    Replies: 6
    Last Post: 01-02-2006, 08:05 PM