8 Replies - 560 Views - Last Post: 09 September 2009 - 11:35 AM Rate Topic: -----

#1 Bada bing  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-September 09

Not looking for answers just some guidance

Posted 08 September 2009 - 07:46 AM

Hi guys, I working on a project and I'm having trouble getting this code to give me a return value. I have tried just about everything, but nothing seems to work. When I compile the program, it starts and shows the locations, but when the user inputs a PurchaseAmount nothing happens. I just want someone to tell me what I'm doing wrong.

#include <stdio.h>
#include <ctype.h>


float TaxCalc(float fPurchaseAmount, float LocalTax);
float Total(float fPurchaseAmount, float TaxAmount);

int main ()
{
int hold;
int iLocation = '\0';
float fPurchaseAmount = '\0';
float Total = '\0';
float TaxAmount = '\0';
float LocalTax = '\0';

	
	printf("\n\tKUDLER FINE FOODS POINT OF SALE SYSTEM\n"); // main menu screen for sales				
	printf("\nPlease select your location\n");		// Users can select their location and the system will
	printf("\n1\tDel Mar\n");						// configure the area tax.
	printf("\n2\tEncinitas\n");
	printf("\n3\tLa Jolla\n");
	scanf_s("%d",&iLocation);


	
	
	if (iLocation == 1)//<-----Main menu for selected location appears
	{
	 
			printf("\n\t***DEL MAR***\n");
			printf("\nPlease input your purchase amount: ");
			scanf_s("%f",&fPurchaseAmount);
			printf("Tax:$%.2f\n",TaxCalc(fPurchaseAmount,TaxAmount));//<-----should calculate and populate tax amount
			printf("Your total comes to $%.2f\n",Total);//<------The total function adds the taxcalc and purchase amount together
			scanf_s("%d",&hold);
	}
			
	if (iLocation == 2)
	{
			printf("\n\t***ENCINITAS***\n");
			printf("\nPlease input your purchase amount: ");
			scanf_s("%f",&fPurchaseAmount);
			printf("Tax:$%.2f\n",TaxCalc(fPurchaseAmount,TaxAmount));
			printf("Your total comes to $%.2f\n",Total);
			scanf_s("%d",&hold);
	}

	if(iLocation == 3)
	{
			printf("\n\t***LA JOLLA***\n");
			printf("\nPlease input your purchase amount: ");
			scanf_s("%f",&fPurchaseAmount);
			printf("Tax:$%.2f\n",TaxCalc(fPurchaseAmount,TaxAmount));
			printf("Your total comes to $%.2f\n",Total);
			scanf_s("%d",&hold);
	}
	
 else 
	{
		printf("\nInvalid option\n");//<--------Displays for invaild input
	}
	
	
}

float LocalTax(int iLocation)//This function designates the tax to the selected location

{

	

	float TaxAmount = 0.0;	

	switch (iLocation){			//<-----Used to switch assign tax amount to selected location.

	case 1: 
			TaxAmount = 7.25;
			break;
			

	case 2:

			TaxAmount = 7.5;
			break;
			

	case 3:

			TaxAmount = 7.75;
			break;
			

 
	} 

 
	return TaxAmount;

}


	
float Total(float fPurchaseAmount, float TaxCalc)//  This function creates the total price by adding the cost with the tax amt
{
	return (fPurchaseAmount + TaxCalc);
}

float TaxCalc(float fPurchaseAmount, float TaxAmount)//This function creates the tax amount by multiplying the purchase 
													// amount with the local tax and dividing by 100.
{
	return (fPurchaseAmount * (TaxCalc/100));
}



Is This A Good Question/Topic? 0
  • +

Replies To: Not looking for answers just some guidance

#2 Mowgef  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 245
  • Joined: 01-May 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 07:55 AM

Welcome to D.I.C.

My guess would be this line:
	return (fPurchaseAmount * (TaxCalc/100.0));


Shouldn't it be:
	return (fPurchaseAmount * (TaxAmount/100.0)); 

This post has been edited by Mowgef: 08 September 2009 - 07:55 AM

Was This Post Helpful? 0
  • +
  • -

#3 Bada bing  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-September 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 08:20 AM

View PostMowgef, on 8 Sep, 2009 - 06:55 AM, said:

Welcome to D.I.C.

My guess would be this line:
	return (fPurchaseAmount * (TaxCalc/100.0));


Shouldn't it be:
	return (fPurchaseAmount * (TaxAmount/100.0)); 


Thank you for your response. I actually originally had it set that way "return (fPurchaseAmount * (TaxAmount/100.0))", I have been toying with it all night and forgot to change it. It still shows the "tax amount" and "total" at 0.00 when a purchase amount is input.
Was This Post Helpful? 0
  • +
  • -

#4 nathanpc  Icon User is offline

  • SCIENCE!
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 08:52 AM

Welcome to D.I.C!
And enjoy this very nice community!
Was This Post Helpful? 0
  • +
  • -

#5 dr_spitfire  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 99
  • Joined: 13-August 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 02:18 PM

It appears you are not giving tax amount a value before you pass it to the function taxCalc

make sure when the user picks a location you give the taxAmount a value, before passing it to the taxCalc function otherwise you'll be multiplying by 0/100
Was This Post Helpful? 0
  • +
  • -

#6 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1102
  • View blog
  • Posts: 4,597
  • Joined: 09-June 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 04:21 PM

you also are not returning value for main, which is a no no
Was This Post Helpful? 0
  • +
  • -

#7 Bada bing  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-September 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 06:37 PM

View Postnathanpc, on 8 Sep, 2009 - 07:52 AM, said:

Welcome to D.I.C!
And enjoy this very nice community!


All of you are amazing. Thank you!!
Was This Post Helpful? 0
  • +
  • -

#8 Mowgef  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 245
  • Joined: 01-May 09

Re: Not looking for answers just some guidance

Posted 08 September 2009 - 06:50 PM

Also, it doesn't look like it is changing the float Total at all.
Was This Post Helpful? 0
  • +
  • -

#9 dr_spitfire  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 99
  • Joined: 13-August 09

Re: Not looking for answers just some guidance

Posted 09 September 2009 - 11:35 AM

see I wasn't sure about that because he named all the functions the same as his variables and so unless this is a top secret C++ thing I've never heard about I was going to complain about that...

if you call the local tax function and change "Total" in the display line to "Total(fPurchaseAmount, TaxCalc)" I think it might work...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1