Mail Archives: djgpp/2000/04/13/22:25:58
I did all these progs (except quad) in my c++1 class :-)
I'll include just main functions, if you need to spread them out or
something, u're gonna have to do it yourself. Include your files and
blah blah blah for each....
Payroll:
int main(){
clrscr();
int pay;
cout<<"Enter Pay Rate:";
cin>>pay;
int hours;
cout<<"Enter hours worked:";
cin>>hours;
cout<<"The total Pay is "<<pay*hours<<" dollars.";
getch();
return 0;
}
Time (I don't know how you enter this. If you enter it as hour (space)
min this works, if both are am, or pm. Otherwise, i don't know.)
int main(){
clrscr();
cout<<"Start Time (hour space min):";
int hourstart, minstart, hourend, minend;
cin>>hourstart>>minstart; //This works because (space is a
//string delimiter, ends cin.
cout<<"End time (hour space min):";
cin>>hourend>>minend;
int hourdiff, mindiff;
hourdiff=hourend-hourstart;
mindiff=minedn-minstart;
cout<<"Person was there for "<<hourdiff<<":"<<mindiff<<
" time.";
getch();
return 0;
}
Change-this will sometimes throw an extra penny in, i don't know y.
int main()
{
clrscr();
char yesOrNo='y';
do{
float mon;
int twenties, tens, fives, ones, qs, ds, ns, ps;
cout<<"How much money do you want to make change out of?";
cin>>mon;
cout<<endl<<endl;
twenties=mon/20;
mon-=twenties*20;
tens=mon/10;
mon-=tens*10;
fives=mon/5;
mon-=fives*5;
ones=mon/1;
mon-=ones;
mon*=100;
qs=mon/25;
mon-=qs*25;
ds=mon/10;
mon-=ds*10;
ns=mon/5;
mon-=ns*5;
ps=mon;
cout<<"Twenties: "<<twenties<<endl;
cout<<"Tens: "<<tens<<endl;
cout<<"Fives: "<<fives<<endl;
cout<<"Ones: "<<ones<<endl;
cout<<"Quarters: "<<qs<<endl;
cout<<"Dimes: "<<ds<<endl;
cout<<"Nickels: "<<ns<<endl;
cout<<"Pennies: "<<ps<<endl;
getch();
cout<<"Do you want to run again?";
cin>>yesOrNo;}while (yesOrNo=='y' || yesOrNo=='Y');
return 0;
}
P.S. Tell me how horrible my code is. Please, i want to know.
"Russell Roberts" <moonhunter AT mackom DOT com> wrote:
>Hi,
>
>I am very new to this whole programming stuff and I am in a real pickle. I
>took a class here this semester that was suppose to be an intro to computer
>science and low and behold I discovered that it was in reality a programming
>class. More specifically Borland C++. The instructor has done a very poor
>job this semester with making sure that the basic concepts of writing in
>this language are understood by all of her students. I for one am one of
>them. What I need are some examples of some source code so that I have a
>foundation to build off of so that I can complete my programs. I have 4
>programs left for this semester
>
>Change- Calculate change to be returned broke down in the various
>denominations
>Quadratic-Don't have a clue
>Time difference- To calculate amount of time a person is at a place
>Payroll-Calculate amount of pay based on persons hours worked * Pay rate
>
>
>I could do most of this using a spreadsheet but I have absolutely no idea
>where to begin in C++. Could anybody out there lend a helping hand?
>
>Most sincerely confused
>
>Russ
>
>--
>"That which does not kill us makes us stronger" - Friedrich Nietzsche
>
>
- Raw text -