help

checks

Page 1 of 1

9 Replies - 1107 Views - Last Post: 31 August 2001 - 09:25 AM Rate Topic: -----

#1 monkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 24-August 01

help

Posted 24 August 2001 - 09:14 AM

I needs help withn my program.
I can't get it to run through without asking to play again, and when it does go through, it doesn't keep the check number and add one to it.

here is my code:
------------------------------------------------------------

#include <iostream.h>
#include <math.h>
#include <stdlib.h>
int k, n, amount;
double gross, state, fed, deduc, overtim;
double overtime, total, hours, all;
char emp[3], dat[18], name[21], ss[15], nam[20], order[30];
void title();
void employees();
void date();
void comp_name();
void soc_sec();
void paidto();
void names();
void head();
void input();
void ender();
main()
{
    title();
    return 0;
}
void title()
{
    cout<<"Wlcome to your checkbook
";
    employees();
}
void employees()
{
    cout<<"How many employees do you have?
";
    cin.get(emp, 3);
    cin.ignore(80, '
');
    date();
}
void date()
{
    system("cls");
    cout<<"What is todays date?
";
    cin.get(dat, 18);
    cin.ignore(80, '
');
    comp_name();
}
void comp_name()
{
    system("cls");
    cout<<"What is your companies name?
";
    cin.get(name, 21);
    cin.ignore(80, '
');
    paidto();
}
void paidto()
{
    cout<<"Who is the check for?
";
    cin.get(order, 30);
    cin.ignore(80, '
');
    soc_sec();
}
void soc_sec()
{
    cout<<"What is the social security number?
";
    cin.get(ss, 12);
    cin.ignore(80, '
'');
    names();
}
void names()
{
system("cls");
cout<<"Please type in your name, followed by enter.  (ex: John Doe)

";
cin.get(nam, 20);
cin.ignore(80, '
');
input();}
void input()
{system("cls");
cout<<"Please fill out the following by entering the correct numbers
";
cout<<"              and then pressing enter after each.

";
cout<<"Total hours worked :
";
cin>>hours;
cout<<"Overtime hours :
";
cin>>overtim;
cout<<"Money made per hour:
";
cin>>mon1;
cout<<"What is the state tax?
";
cin>>stat;
cout<<"What is the federal tax?
";
cin>>feder;
total=hours * mon1;
if (overtim>0)
{overtim=hours - 40;
overtime=overtim*mon1+mon1*.5;}
else
{overtime=0;}
head();}
void head()
{system("cls");
n=0;
k=n+1;
gross=total+overtime;
state=gross*stat;
fed=gross*feder;
deduc=state+fed;
all=gross-state-fed;
for(n=0; n<=10; n++)
{cout<<"///////////////////////////////////////////////////////////////////
";
cout<<"/"<<name<<"               Check #"<<k<<"      Date: "<<dat<<"      
";
cout<<"/C++ Advanced Avenue                                              
";
cout<<"/Rio Rancho, NM 87124                                              
";
cout<<"/                                                                  
";
cout<<"/Pay to the order of : "<<order<<"                                
";
cout<<"/Social Security # :"<<ss<<"                                      
";
cout<<"/                                                                  
";
cout<<"/The Amount Of :$"<<all<<"                                        
";
cout<<"/                                           "<<nam<<"              
";
cout<<"/                                           Owner                  
";
cout<<"///////////////////////////////////////////////////////////////////
";
break;}
cout<<"Total Hours worked :"<<hours<<" at $"<<mon1<<" per hour.
";
cout<<"Regular pay :  $ "<<total<<"
";
cout<<"Overtime pay : $ "<<overtime<<"
";
cout<<"-------------------------------
";
cout<<"Gross Pay :         $ "<<gross<<"  
";
cout<<"State Tax :         $ "<<state<<" at "<<stat<<"%
";
cout<<"Federal Tax :       $ "<<fed<<" at "<<feder<<"%
";
cout<<"Total Deductions :  $ "<<deduc<<'
';
cout<<"-------------------------------
";
cout<<"Net Pay :           $ "<<all<<'
';
ender();}
void ender()
{char y_n;
cout<<"would you like to keep going?
";
cin>>y_n;
switch (y_n)
{case 'y':
{date();}
case 'n':
{system ("cls");
cout<<"Goodbye

";}
default:
{system ("cls");
cout<<"Please follow directions
";
ender();}}}



Is This A Good Question/Topic? 0
  • +

Replies To: help

#2 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: help

Posted 24 August 2001 - 03:01 PM

ummm can you elaborate on youre error. like what is supposed to happening and what is happening instead.

Im not quite sure what the question is.

Was This Post Helpful? 0
  • +
  • -

#3 Teckwiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: --

Re: help

Posted 26 August 2001 - 11:17 AM

The only thing I get from that message is that he is making checks, but the check number isn't going up by one properly, or at all.
(Check #1, Check #2, Check #3, etc.) The code for that part looks fine to me (I'm still a beginner mind you).
Anyone else have any ideas?
Was This Post Helpful? 0
  • +
  • -

#4 monkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 24-August 01

Re: help

Posted 27 August 2001 - 09:12 AM

My problem is just what Jason said, and also that I can't get my program to return to the questions (what is the date, etc...) so the user can enter them. Also, sometimes, when I click y to play again, it skips over the employees function.
Was This Post Helpful? 0
  • +
  • -

#5 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: help

Posted 27 August 2001 - 03:43 PM

Um...I realize that you're probably doing this assignment for a class, so hopefully (both for your sake and everyone else in the class) I'm not contradicting your teacher...but I'd really recomment not linking the functions together like that. It makes it tougher to debug it, tougher to read it, can pose some problems once you start using local varialbes (and even when you don't), and it doesn't serve a greater purpose. I'd rethink your design, if you have time.
(begin edit)
Just some explanation of myself here.
One of the reasons I say that you shouldn't do that is because the program never leaves any of the functions until the very end of the program. Each time you enter a new function, certain information about the old function is saved, including any local variables that were declared. So say you have two checks to output. The function calls will look like this:
title
employees
 date
  comp_name
   paidto
    soc_sec
     names
      ender
       (note that I skip employees() here...that's why it wouldn't show up for you. In ender(), you call date() to start the loop over again, instead of employees())
       date
        comp_name
         ...
          names
           ender
Each of these calls is gonna put more stuff on the stack, and if you do it enough times, you'll get a segmentation fault.
Just a quick note--I'm not trying to be harsh or cut you up here. Just pointing out and explaining myself. :)
(end edit)
With that said...look at the statement just above "k=n+1". You assign 0 to n each time. That's why it's never going up--if you're trying to initialize n to 0, you should do it outside of the "loop" you have going there. Along those lines, you don't even need the variable k, unless you use it for something other than the cout statement that follows a few lines later. All you need to do is increment n by one each time.
Let me know if you have any other questions, and I'll try to clarify myself for you.

(Edited by malkiri at 1:05 pm on Aug. 27, 2001)

Was This Post Helpful? 0
  • +
  • -

#6 monkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 24-August 01

Re: help

Posted 28 August 2001 - 08:12 AM

I have changed my program some so that they say whether or not they want to use the checkbook before they say how many employees they have. I figured that if they want to play, then it would ask them for the employee number and then I could use a for loop somewhere, but, when it asks for the employees, I type in a number, and then it skips the date function, and also I tried the for loop, and I couldn't figure it out.
code:
------------------------------------------------------------
//Checkbook
//By : Jeff Golik
//Block 2
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
int k, n, amount;
double gross, state, fed, deduc, overtim, overtime, total, hours, all;
float mon1, stat, feder;
char emp, dat[18], name[21], ss[15], nam[20], order[30];
void title();
void do_again();
void date();
void comp_name();
void soc_sec();
void paidto();
void names();
void head();
void input();
main()
{title();
return 0;}
void title()
{cout<<"Welcome to your checkbook and totaler.


";
do_again();}
void do_again()
{char ans;
do
{cout<<"Would you like to use your checkbook?
";
cin>>ans;
switch (ans)
{case 'n':
case 'N':
{cout<<"GoodBye
";
break;}
default:
{cout<<"Error
";
break;}
case 'y':
case 'Y':
{cout<<"How many employees do you have?
";
cout<<"     and then press enter

";
cin>>emp;
date();
break;}}}while (ans!='n');}
void date()
{system("cls");
cout<<"What is todays date?    Ex.: August 31, 2001
";
cout<<"         and then press enter

";
cin.get(dat, 18);
cin.ignore(80, '
');
comp_name();}
void comp_name()
{system("cls");
cout<<"What is your companies name (up to 20 characters)?
";
cout<<"            and then press enter

";
cin.get(name, 21);
cin.ignore(80, '
');
paidto();}
void paidto()
{system("cls");
cout<<"Who is the check for?   Then press enter.

";
cin.get(order, 30);
cin.ignore(80, '
');
soc_sec();}
void soc_sec()
{system("cls");
cout<<"What is their social security number?      (ex:  123-45-6789)
";
cout<<"       and then press enter

";
cin.get(ss, 12);
cin.ignore(80, '
');
names();}
void names()
{
system("cls");
cout<<"Please type in your name, followed by enter.  (ex: John Doe)

";
cin.get(nam, 20);
cin.ignore(80, '
');
input();}
void input()
{system("cls");
cout<<"Please fill out the following by entering the correct numbers
";
cout<<"              and then pressing enter after each.

";
cout<<"Total hours worked :
";
cin>>hours;
cout<<"Overtime hours :
";
cin>>overtim;
cout<<"Money made per hour:
";
cin>>mon1;
cout<<"What is the state tax?
";
cin>>stat;
cout<<"What is the federal tax?
";
cin>>feder;
total=hours * mon1;
if (overtim>0)
{overtim=hours - 40;
overtime=overtim*mon1+mon1*.5;}
else
{overtime=0;}
head();}
void head()
{system("cls");
n=0;
k=n+1;
gross=total+overtime;
state=gross*stat;
fed=gross*feder;
deduc=state+fed;
all=gross-state-fed;
for(n=0; n<=10; n++)
{cout<<"///////////////////////////////////////////////////////////////////
";
cout<<"/"<<name<<"               Check #"<<k<<"      Date: "<<dat<<"      
";
cout<<"/C++ Advanced Avenue                                              
";
cout<<"/Rio Rancho, NM 87124                                              
";
cout<<"/                                                                  
";
cout<<"/Pay to the order of : "<<order<<"                                
";
cout<<"/Social Security # :"<<ss<<"                                      
";
cout<<"/                                                                  
";
cout<<"/The Amount Of :$"<<all<<"                                        
";
cout<<"/                                           "<<nam<<"              
";
cout<<"/                                           Owner                  
";
cout<<"///////////////////////////////////////////////////////////////////
";
break;}
cout<<"Total Hours worked :"<<hours<<" at $"<<mon1<<" per hour.
";
cout<<"Regular pay :  $ "<<total<<"
";
cout<<"Overtime pay : $ "<<overtime<<"
";
cout<<"-------------------------------
";
cout<<"Gross Pay :         $ "<<gross<<"  
";
cout<<"State Tax :         $ "<<state<<" at "<<stat<<"%
";
cout<<"Federal Tax :       $ "<<fed<<" at "<<feder<<"%
";
cout<<"Total Deductions :  $ "<<deduc<<'
';
cout<<"-------------------------------
";
cout<<"Net Pay :           $ "<<all<<'
';}

------------------------------------------------------------

any ideas?

(Edited by monkey at 10:14 am on Aug. 28, 2001)

(Edited by runtime error at 1:12 pm on Aug. 30, 2001)

Was This Post Helpful? 0
  • +
  • -

#7 monkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 24-August 01

Re: help

Posted 28 August 2001 - 08:53 AM

I just tried to combine the date and the companies name into one function, and that doesn't work either, it still skips the date.
code:
------------------------------------------------------------

....
void date_comp_name()
{system("cls");
cout<<"What is todays date?    Ex.: August 31, 2001
";
cout<<"         and then press enter

";
cin.get(dat, 18);
cin.ignore(80, '
');
cout<<"What is your companies name (up to 20 characters)?
";
cout<<"            and then press enter

";
cin.get(name, 21);
cin.ignore(80, '
');
paidto();}
------------------------------------------------------------
any ideas?

Was This Post Helpful? 0
  • +
  • -

#8 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: help

Posted 28 August 2001 - 10:36 AM

I think the only truly helpful suggestion I can give you without rewriting your code for you is to take a step back and rethink everything. I'd strongly recommend starting fresh, as well. Think about what you want to accomplish in very high level terms. If I understand your assignment correctly, you have to produce a program that will format and print out one or more sets of data that the user inputs. You don't have to get fancy with it, even if you're required to use functions by the assignment. Think of it in pseudocode:

Until the user decides to stop,
 Collect the data
 Print out the data

Of course, I'm purposely not getting specific. I think that if you reconceptualize the problem, you'll have a much easier time trying to both code and debug it. Good luck!

Was This Post Helpful? 0
  • +
  • -

#9 monkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 24-August 01

Re: help

Posted 30 August 2001 - 09:15 AM

That's what I'm having trouble with, I can't figure out the code to do the loop for the user to go through so many times. Once I figure that code out, I'll be set.
Was This Post Helpful? 0
  • +
  • -

#10 monkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 24-August 01

Re: help

Posted 31 August 2001 - 09:25 AM

Does anybody have any ideas why my program likes to skip the function right after the do_again function? I ask if they want to play, and if they enter y, then it goes to the
date_comp_name() function, but it skips the date part of the function. Can anyone help me?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1