Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,132 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,795 people online right now. Registration is fast and FREE... Join Now!




idiot proofing

 
Reply to this topicStart new topic

idiot proofing, not to allow letters to be entered when asked for numbers

220018183
17 Apr, 2007 - 06:14 AM
Post #1

New D.I.C Head
*

Joined: 16 Apr, 2007
Posts: 5


My Contributions
when i ask for employees on payroll it allows user to enter letters

CODE

//program 9
//calculates a companys payroll
//by gene garcia
//c++ b1 mrs. robinson
//4/10/2007

#include <iostream.h>
main()
{
    char  employees_name, employees_status;
    int    employees, count=0;
    float employees_pay, employees_gross,employees_hours;

    cout<<"\n\n\n\nWelcome!\n";
    cout<<"\nPayroll System\n";
    cout<<"Copyright  2007\n";


    cout<<"How many employees on your payroll?\n";// Allows user to enter number of employees
    cin>>employees;
    cin.ignore(80, '\n');
    

    
    do
    {
    cout<<"enter employees name\n";// Allows user to enter the employee's name
    cin>>employees_name;
    cin.ignore(80, '\n');
    cout<<"Enter employees status\n(P-part time,F-full time,T-temperary)\n";//Allows user to enter employees status
    cin>>employees_status;
    if (employees_status == 'P')
        employees_pay=9.55;
    if (employees_status =='F')
        employees_pay=15.00;                
    if (employees_status == 'T')
        employees_pay=7.25;
    
    cout<<"Enter employees hours.\n";// allows user to enter x amount of hours
    cin>>employees_hours;

    
    if(employees_hours > 40)
        employees_gross= (employees_pay*40)+(employees_hours-40) * ( 1.5 * employees_pay);
    else
        employees_gross= employees_pay * employees_hours;
    count++;

    cout<<employees_name<<", "<<employees_status<<"\t"<<employees_gross<<"\n";


    }while(count<employees);



    return 0;
}

User is offlineProfile CardPM
+Quote Post

Pontus
RE: Idiot Proofing
17 Apr, 2007 - 08:31 AM
Post #2

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 529



Thanked: 2 times
Dream Kudos: 275
My Contributions
try this:
CODE
if((number >= 0) ||(number <=0)){}//the input is a number


This post has been edited by manhaeve5: 17 Apr, 2007 - 08:32 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:25PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month