C programming help!

aarochordidae

Junior Member
Nov 28, 2000
6
0
0
The program <scroll down to the bottom> doesn't run properly. Can someone please check my program if it does the following:
ask the user:
sqfeet of store(min 4000 and max 8000)
total square feet of building (min=sqfeet of store, max=32000)
sqfeet of warhouse space(min=2000, max=sqfeet of store-1000)

sqfeet of store MUST be 25% of building if not, stop the program, ask the user if they want to continue to analyze another building, and repeat all the questions

sqfeet of warehouse must be 30% of store if not,stop the program, ask the user if they want to continue to analyze another building, and repeat all the questions


use the following functions:
int GetSqfeet(int min, int max)
Used to input all of the square footage amounts. THe input value must be >=min and <=max. The building cannot be processed until the square footage is correct. Note that min and max will be different depending on which value is being input.

int inRange(int sqfeet, int minpercent, int total)
used to verify the secondary conditions. Returns a 1 if its within range or a 0 if its to be rejected.

WHAT I AM HAVING TROUBLE WITH:
a) if I enter for example the sqfeet of the store to be 5000 and the building to be 10000( it is 50% of the building), it still asks me if I want to continue but the percentage is greater than 25.

b) When it does ask me if I want to continue, if I press no, it goes on again.
c) when it repeats, it doesn't start from the beginning (asking the sqfeet of store). It jumps to the sqfeet of the warehouse.

IF U RUN THE PROGRAM, U WILL NOTICE ALL THOSE ERRORS.
I WOULD REALLLLLLYYYY APPRECIATE IF SOMEONE HELPS ME OUT.



# include <stdio.h>
int GetSqfeet();
int inRange();
main()
{

int min=4000;
int max=8000;
int stfeet;
int sqfeet_building;
int minpercent;
int total;
int sqwarehouse;
int range_building;
int range_warehouse;
char answer;
int sqfeet;
clrscr();
do
{

stfeet=GetSqfeet(min,max);
min=stfeet;
max=32000;
sqfeet_building=GetSqfeet(min,max);
total=sqfeet_building;
minpercent=25;
sqfeet=stfeet;
range_building=inRange(sqfeet,minpercent, total);

if (range_building==0)
{
printf(&quot;Do you wish to continue&quot;);
answer=getche();
}
min=2000;
max=stfeet-1000;
sqwarehouse=GetSqfeet(min,max);
sqfeet=sqwarehouse;
total= stfeet;
minpercent=30;
range_warehouse=inRange(sqfeet, minpercent, total);


if(range_warehouse==0)
{
printf(&quot;Do you wish to continue&quot;);
answer=getche();
}


} while(answer!='y' || answer!='Y');
return;
}

int GetSqfeet(int min, int max)
{
int sqfeet;
if (max==8000)
{ printf(&quot;Enter the square footage of the store: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}

if(max==32000)
{ printf(&quot;Enter the square footage of the building: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}
if(min==2000)
{ printf(&quot;Enter the square footage of the warehouse: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}
do
{
if((sqfeet<min) || (sqfeet>max))
{
printf(&quot;Sorry, that is not within the range:&quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);
}
}while (sqfeet<min || sqfeet>max);
return(sqfeet);
}

int inRange(int sqfeet, int minpercent, int total)
{
int percent;
int range;
percent=(sqfeet/total)*100;
if(percent>=minpercent)
range=1;
else
range=0;
return(range);
}
 

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
Really not sure the object of the program but to address the following question:

) when it repeats, it doesn't start from the beginning (asking the sqfeet of store). It jumps to the sqfeet of the warehouse.

If you want to start fresh with each iteration, you will need to keep resetting int min=4000;
int max=8000, at the top of the loop.

do {
int min=4000; //add these here
int max=8000; //add these here

}while;

//If max does not get set to 8000 at the beginning of the loop, this section of code will be skipped.
if (max==8000)
{ printf(&quot;Enter the square footage of the store: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}


 

aarochordidae

Junior Member
Nov 28, 2000
6
0
0
Thank you gittyup.
Here is my revised code. One problem still exists. That is for example if I say the sqfeet of the store is 5000 and the building is10000. The sqfeet of the store is >25% of the building, right? But it continues to ask do u want to continue. The program is supposed to go on to ask the sqfeet of the warehouse if the above conditions were satisfied and they were. Can someone please help with that question?
# include <stdio.h>
int GetSqfeet();
int inRange();
main()
{

int min=4000;
int max=8000;
int stfeet;
int sqfeet_building;
int minpercent;
int total;
int sqwarehouse;
int range_building=0;
int range_warehouse=0;
char answer;
int sqfeet;
clrscr();
do
{

int min=4000;
int max=8000;
stfeet=GetSqfeet(min,max);
min=stfeet;
max=32000;
sqfeet_building=GetSqfeet(min,max);
total=sqfeet_building;
minpercent=25;
sqfeet=stfeet;
range_building=inRange(sqfeet,minpercent, total);

if (range_building==0)
{
printf(&quot;Do you wish to continue&quot;);
answer=getche();
if(('N'==answer) || ('n'==answer))
break;
else
continue;
}
min=2000;
max=stfeet-1000;
sqwarehouse=GetSqfeet(min,max);
sqfeet=0;
sqfeet=sqwarehouse;
total= stfeet;
minpercent=30;
range_warehouse=inRange(sqfeet, minpercent, total);


if(range_warehouse==0)
{
printf(&quot;Do you wish to continue&quot;);
answer=getche();
if(('N'==answer) || ('n'==answer))
break;
else
continue;
}


} while(answer!='y' || answer!='Y');
return;
}

int GetSqfeet(int min, int max)
{
int sqfeet;
if (8000==max)
{ printf(&quot;Enter the square footage of the store: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}

if(32000==max)
{ printf(&quot;Enter the square footage of the building: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}
if(2000==min)
{ printf(&quot;Enter the square footage of the warehouse: &quot;);
scanf(&quot;%d&quot;,&amp;sqfeet);}
while((sqfeet<min) || (sqfeet>max))
{
printf(&quot;Sorry, that is not within the range:%d to %d&quot;,min,max);
scanf(&quot;%d&quot;,&amp;sqfeet);
}
return(sqfeet);
}

int inRange(int sqfeet, int minpercent, int total)
{
int percent;
int range;
percent=(sqfeet*100/total);


return(percent>=minpercent);
}
 

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
What value is being returned from range_warehouse=inRange(sqfeet, minpercent, total);?
Print out that value, it must be 0?