Mail Archives: djgpp/1998/10/13/00:41:49
Message-ID: | <3622B158.6DC9DC07@nceye.net>
|
From: | Alexei Akimov <sabrah AT nceye DOT net>
|
X-Mailer: | Mozilla 4.05 [en] (Win95; I)
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | function basics - mem. address
|
Lines: | 171
|
Date: | Mon, 12 Oct 1998 21:48:08 -0400
|
NNTP-Posting-Host: | 206.107.98.70
|
X-Trace: | news14.ispnews.com 908243294 206.107.98.70 (Mon, 12 Oct 1998 21:48:14 EDT)
|
NNTP-Posting-Date: | Mon, 12 Oct 1998 21:48:14 EDT
|
Organization: | ISPNews http://ispnews.com
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hya,
and thanx agian for helping me. I certainly understood a bit about
functions,
but still not enough to resolve another stumbling block (for me).
Could u plz have a look a it and point me out, how I should do it?
Below is the piece that I working on. The first function is working, but
there something wrong with data types or formats. It prints everything,
except for the last interger. If u r interested to see the whole thing,
just scroll down, plz.
Thank you - I really do appreciate, Alex
#include <stdio.h>
#include <conio.h>
void prompt(int &hrs1, char &ch1, int &mnts1,int &hrStop1,int
&mntStop1)
{
printf ("Plz carve your nums");
scanf ("%d%c%d", &hrs1, &ch1, &mnts1);
printf("U left office at: ");
scanf ("%d%c%d", &hrStop1, &ch1, &mntStop1);
return;
}
void mntpositive(int &hrs1, int &hrStop1, int &Allhrs1)
{
if (hrs1>=8&&hrs1<=12&&hrStop1<8&&hrStop1>0)//began before 12 &
finished after
Allhrs1=12-hrs1;
Allhrs1=Allhrs1+hrStop1;
if (hrs1>=8&&hrs1<12&&hrStop1>=8&&hrStop1<=12)//began & finished
before 12
Allhrs1=hrStop1-hrs1;
else if (hrs1<7&&hrs1>0&&hrStop1<=7&&hrStop1>0)//began & finished
after 12
Allhrs1=hrStop1-hrs1;
return;
}
void main (void)
{ int days, Allmnts, totalHrs, Allhrs, totalMnts;
char ch;
clrscr();
int hrs, mnts, hrStop, mntStop;
prompt(hrs, ch, mnts, hrStop, mntStop);
if (mnts<60&&mnts>=0&&mntStop<60&&mntStop>=0)//minutes are valid
initially
Allmnts=mntStop-mnts;
if (Allmnts>=0&&Allmnts<60&&mntStop>=mnts)//entries with positive
minutes difference
{int hrs, hrStop, Allhrs;
mntpositive(hrs, hrStop, Allhrs);
}
printf("\n\tHere they are:\n\t%d and %d and %d and %d and %d", hrs,
mnts, mntStop, hrStop, Allhrs);
}
And here's the whole program, if it's helpful .
#include <stdio.h>
#include <conio.h>
void prompt(int &hrs1, char &ch1, int &mnts1,int &hrStop1,int
&mntStop1)
{
printf ("Plz carve your nums");
scanf ("%d%c%d", &hrs1, &ch1, &mnts1);
printf("U left office at: ");
scanf ("%d%c%d", &hrStop1, &ch1, &mntStop1);
}
int main ()
{ int hrs, mnts, hrStop, mntStop, Allhrs, Allmnts, days, totalHrs=0,
totalMnts=0, extra;
char ch;
for (days=0; days<5; days++)
{ clrscr();
int hrs, mnts, hrStop, mntStop;
char ch;
prompt(hrs, ch, mnts, hrStop, mntStop);
if (mnts<60&&mnts>=0&&mntStop<60&&mntStop>=0)//minutes are valid
initially
Allmnts=mntStop-mnts;
if (Allmnts>=0&&Allmnts<60&&mntStop>=mnts)//entries with positive
minutes difference
{
if (hrs>=8&&hrs<=12&&hrStop<8&&hrStop>0)//began before 12 & finished
after
Allhrs=12-hrs;
Allhrs=Allhrs+hrStop;
if (hrs>=8&&hrs<12&&hrStop>=8&&hrStop<=12)//began & finished before
12
Allhrs=hrStop-hrs;
else if (hrs<7&&hrs>0&&hrStop<=7&&hrStop>0)//began & finished after
12
Allhrs=hrStop-hrs;
}
else if (Allmnts<0&&Allmnts>-60)//entries with a negative minutes
difference
{
if (hrs>=8&&hrs<=12&&hrStop<8&&hrStop>0)//began before 12 & finished
after
Allhrs=11-hrs;
Allhrs=Allhrs+hrStop;
if (hrs>=8&&hrs<=12&&hrStop>=8&&hrStop<=12)//began & finished before
12
Allhrs=hrStop-hrs-1;
else if (hrs<8&&hrs>0&&hrStop<8&&hrStop>0)//began & finished after
12
Allhrs=hrStop-hrs-1;
Allmnts=60+Allmnts;
}
totalHrs=totalHrs+Allhrs;
totalMnts=totalMnts+Allmnts;
}
float rate, hrWage, mntWage, regWage, SuperWage, totalWage;
printf ("Enter desired pay per hour: ");
scanf ("%f", &rate);
if (totalMnts>=60)
{
extra=totalMnts/60;
totalMnts=totalMnts%60;
totalHrs=totalHrs+extra;
}
if (totalHrs>40)
{ regWage=rate*40;
SuperWage=(totalHrs-40)*1.5f*rate;
mntWage=(rate/60)*totalMnts;
totalWage=regWage+SuperWage+mntWage;
}
else
{
SuperWage=0;
mntWage=(rate/60)*totalMnts;
totalWage=(rate*totalHrs)+mntWage;
}
printf ("\n\tYour regular pay is $%7.2f,\n overtime pay $%7.2f,\n\t and
total pay $%7.2f\n\t", regWage, SuperWage, totalWage);
return 0;
}
- Raw text -