delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/13/13:03:08

From: sabrah AT carolina DOT net (Al)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: function basics - mem. address
Message-ID: <36237b08.902850@news.intrstar.net>
References: <3622B158 DOT 6DC9DC07 AT nceye DOT net>
X-Newsreader: Forte Free Agent 1.11/32.235
Lines: 167
Date: Tue, 13 Oct 1998 16:13:03 GMT
NNTP-Posting-Host: 206.107.98.37
X-Trace: news14.ispnews.com 908295193 206.107.98.37 (Tue, 13 Oct 1998 12:13:13 EDT)
NNTP-Posting-Date: Tue, 13 Oct 1998 12:13:13 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,
I used the debugger and it pointed me out, and I found the problem,
and it runs now as should. If interested, scroll down to see stuff in
square brackets wrong. I declared variables in the main, and then
repeated , when called the second function.
Alexei Akimov wrote:
> 
> Wow, I forgotten to say that gcc (with Rhide) compils everything without
> errors, and displays all intergers, but the last one always has one and
> the same value: 11935696. Probably, it's memory address?
> 
> Alexei Akimov wrote:
> >
> > 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019