Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i have 3 methods the main and 2 others, in one method input is taken from the user and stored as a float in that method, how do i access this float in a seperate method to use it for calculations?

thanks

daniel
 
here is the code i have got so far:-

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

#include <stdio.h>
#define tax 22

int addorder();
int chart();
int percentage();
int average();
int totalcost();

int main(void)
{
char c;

printf(&quot;\n\nWelcome to Mega Burger Ordering system&quot;);
printf(&quot;\n\n***Main Menu***&quot;);
printf(&quot;\n\n1. Add Order&quot;);
printf(&quot;\n2. Chart&quot;);
printf(&quot;\n3. Percentage&quot;);
printf(&quot;\n4. Average&quot;);
printf(&quot;\n5. TotalCost&quot;);
printf(&quot;\n6. EXIT&quot;);

c=toupper(getch());

switch(c)
{

case '1':
addorder();
break;

case '2':
chart();
break;

case '3':
percentage();
break;

case '4':
average();
break;

case '5':
totalcost();
break;

case '6':
printf(&quot;\n\nThank You for using Mega Burger&quot;);
exit(0);
break;

default:
printf(&quot;\n\n\n\n\n\n\n***error***\n\n\n&quot;);
main();
break;

}

return 0;

}


int addorder()
{
char m;
int s, p;
float mprice, sprice, ordtot;

printf(&quot;\n\tMain Meal\t\t\t\tSide Order&quot;);
printf(&quot;\na. Beef Burger\t\t@œ1.50\t\t1. Chips\t\t@œ1.50&quot;);
printf(&quot;\nb. Chichen Bites\t@œ1.60\t\t2. Salad\t\t@œ1.50&quot;);
printf(&quot;\nc. Vege Burger\t\t@œ1.80\t\t3. Baked Potato\t\t@œ1.50&quot;);
printf(&quot;\nd. Breakfast Burger\t@œ1.50\t\t4. None\t\t\t@œ0.00&quot;);
printf(&quot;\ne. Scampi\t\t@œ2.00&quot;);

printf(&quot;\nEnter Meal \t:&quot;);
scanf(&quot;%c&quot;, &m);

printf(&quot;\nEnter Side order\t:&quot;);
scanf(&quot;%d&quot;, &s);

printf(&quot;\nEnter Number of Portions:&quot;);
scanf(&quot;%d&quot;, &p);

switch(m)
{

case 'a':
mprice=1.50;
break;

case 'b':
mprice=1.60;
break;

case 'c':
mprice=1.80;
break;

case 'd':
mprice=1.50;
break;

case 'e':
mprice=2.00;
break;

}

switch(s)
{

case 1:
sprice=1.50;
break;

case 2:
sprice=1.50;
break;

case 3:
sprice=1.50;
break;

case 4:
sprice=0.00;
break;

}

ordtot=(mprice+sprice)*p;

printf(&quot;\nOrder Total: %10.2f&quot;, ordtot);

main();

return 0;
}

int totalcost()
{

printf(&quot;\n\n\nThe totalcost of all orders is: &quot; );
main();
return 0;

}

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

what it needs to do is keep a total of value of all orders placed. How?

another thing it does is after entering an order if i try to order again it skips the main meal entry

sorry for the long post

cheers

daniel
 
Why not just declare the total cost as a global variable. It will remain for the life of the program rather than the life of your function. Mise Le Meas,

Mighty :)
 
hi

i am a complete beginner so could you explain how pls

thanks

daniel
 
Better, have addorder() return a float.

float addorder()
{
/* ... */
ordtot=(mprice+sprice)*p;
return ordtot;
}

int main(void)
{
float total;
/* ... */
total=addorder();
printf(&quot;the total is: %f\n&quot;,total);
}



Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top