14 Replies - 1966 Views - Last Post: 30 August 2012 - 10:37 AM Rate Topic: -----

#1 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 02:15 AM

I can find the where is wrong


this is full code.



#include <stdio.h>
 
float calculate (float);
float display (float);
 



void main(void)
 {
 float ch,qu;
 printf("\n================================================\n");
 printf("\t\tRNR COFFEE SHOP");
 printf("\n================================================\n");
 printf("1. Cappuccino [RM2.00]\n");
 printf("2. Espresso   [RM2.25]\n");
 printf("3. Latte      [RM1.75]\n");
 printf("\n================================================\n");
 printf("Enter your choice: ");
 scanf("%f",&ch);
 printf("\nEnter quantity: ");
 scanf("%f",&qu);

 if (ch ==1)
	{printf("Cappuccino");
  
  calculate(ch);}
  else if  (ch ==2)
	{printf("Espresso");
 
 calculate(ch);}
 else if (ch ==3)
	{printf("Latte");
 
  calculate(ch);}

 else 
	 printf("Inviled number\n");
 
 
 
 return;
 }

 float calculate (float ch,float qu,float price)
 {
	 float sum,price;
 if (ch == 1)
	{printf("Cappuccino");
 price = 2.00;
 sum = qu * price;}
  else if  (ch == 2)
	{ printf("Espresso");
 price = 2.25;
 sum = qu * price;}
 else if (ch == 3)
	{ printf("Latte");
   price = 1.75;
  sum = qu * price;}
  else 
 { printf("Inviled number\n");}
 display (sum);
 
 
return 0;
 }
 float display (float ch,float qu,float sum,float price)
 {
 printf("\n================================================\n");
 printf("\t\tDETAILS");
 printf("\n================================================\n");
 printf("Type : %f",ch);
 printf("Price : %f",price);
 printf("Quantity : %f",qu);
 printf("Total price : %f",sum);





 return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: error C2082: redefinition of formal parameter 'price'

#2 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 02:26 AM

I can find the wrong but I can't make it correct ..
can you help me ..
Was This Post Helpful? 0
  • +
  • -

#3 nuclearfroggy  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 82
  • View blog
  • Posts: 167
  • Joined: 04-August 08

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 02:38 AM

Here the compiler's pretty much told you what's wrong, and should give you a line number which will direct you to the problem. In the parameter list of the function "calculate", one of the parameters is the float "price". You then below define another float called price. This is probably not what you intended, and you can't declare two variables with the same name (in the same scope).

It seems as though you set the price in the function calculate, so you don't really need to pass the price at all. You've also made the return type of the function a float, but you're not really returning anything (just 0). I'm guessing you'll want to return the calculated value sum, which you would do by saying
return sum;


Your indentation is not very consistent or readable. Try and find a recognised style and stick to it. An IDE like Code::Blocks or Visual Studio, or even editor like Notepad++ will make it less painless (if you're not already using an IDE)

Finally, if I'm going to be nitpicky ;) you've used "void main(void)", but main should have an integer return type, so use "int main(void)" or "int main(int argc, char *argv[])". Finally, in the function prototypes (lines 3 and 4) you need to specify the types of all the parameters (you can also include the names if you want). For example, as your code is currently, you'd have
float calculate(float, float, float);

Hope this helps.

This post has been edited by nuclearfroggy: 29 August 2012 - 02:39 AM

Was This Post Helpful? 1
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1579
  • View blog
  • Posts: 3,007
  • Joined: 30-May 10

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 03:15 AM

45 float calculate (float ch,float qu,float price)
46 {
47 float sum,price;
Hey, there it is again - did you see that?
Was This Post Helpful? 1
  • +
  • -

#5 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 07:05 PM

I don't know to be correct.
how i make it correct.
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 710
  • View blog
  • Posts: 2,033
  • Joined: 20-March 10

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 07:13 PM

There are a lot of errors,

so you have to be patient this will take a long time,

a lot of your errors are conceptual understanding failures.

Take your first one..

you forward declare your function calculate as follows..

float calculate (float);

then you implement it as follows...

float calculate (float ch,float qu,float price)
{


make it so your forward declaration matches your implementation..

hint your implementation is correct..

do the same for the other function called display.

This post has been edited by snoopy11: 29 August 2012 - 07:14 PM

Was This Post Helpful? 1
  • +
  • -

#7 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 07:34 PM

because the lecture order therequirements follows:
In main():
1. The system must have a menu to allow their worker to choose type of coffee the customer wants.
2. The system must allow the worker to enter the quantity of coffee that the customer wants.
In calculate():
1. The system must able to do a calculation of payment for the coffee the customer bought.
In display():
1. The system must be able to print receipt to customer stating the type of coffee, the quantity they have bought, the price and total price.
Was This Post Helpful? 0
  • +
  • -

#8 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 710
  • View blog
  • Posts: 2,033
  • Joined: 20-March 10

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 09:54 PM

View PostNeeZaaR, on 30 August 2012 - 02:34 AM, said:

because the lecture order therequirements follows:
In main():
1. The system must have a menu to allow their worker to choose type of coffee the customer wants.
2. The system must allow the worker to enter the quantity of coffee that the customer wants.
In calculate():
1. The system must able to do a calculation of payment for the coffee the customer bought.
In display():
1. The system must be able to print receipt to customer stating the type of coffee, the quantity they have bought, the price and total price.


Yes ok then,

but did you fix the first thing that I mentioned yet ?

line 10 change to
10 float ch,qu,price=0,sum=0;

Next up are lines 24-27

24 if (ch ==1)
25 {printf("Cappuccino");
26
27 calculate(ch);}


should really be

24 if (ch ==1)
25 {printf("Cappuccino");
26 price = 2.00f;
27 sum = calculate(ch,qu,price);}

make those adjustments and then repost your updated code.

Snoopy.

This post has been edited by snoopy11: 29 August 2012 - 10:04 PM

Was This Post Helpful? 1
  • +
  • -

#9 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 10:19 PM

also it is wrong.
now it has a new problem ((fatal error LNK1120: 2 unresolved externals))

#include <stdio.h>
 
float calculate (float);
float display (float);
 


float ch,qu,price=0,sum=0;
void main(void)
 {

 printf("\n================================================\n");
 printf("\t\tRNR COFFEE SHOP");
 printf("\n================================================\n");
 printf("1. Cappuccino [RM2.00]\n");
 printf("2. Espresso   [RM2.25]\n");
 printf("3. Latte      [RM1.75]\n");
 printf("\n================================================\n");
 printf("Enter your choice: ");
 scanf("%f",&ch);
 printf("\nEnter quantity: ");
 scanf("%f",&qu);

 if (ch ==1)
	{printf("Cappuccino");
	 price = 2.00;
  calculate(ch);}
  else if  (ch ==2)
	{printf("Espresso");
	price = 2.25;
 calculate(ch);}
 else if (ch ==3)
	{printf("Latte");
 price = 1.75;
  calculate(ch);}

 else 
	 printf("Inviled number\n");
 
 
 
 return ;
 }

 float calculate (float ch,float qu,float price)
 {
	 
 if (ch == 1)
	{ printf("Cappuccino");
 
 sum = qu * price;
 }
  else if  (ch == 2)
	{ printf("Espresso");
 sum = qu * price;}
 else if (ch == 3)
	{ printf("Latte");
  sum = qu * price;}
  else 
 { printf("Inviled number\n");}
 display (sum);
 
 
return 0;
 }
 float display (float ch,float qu,float sum,float price)
 {
 printf("\n================================================\n");
 printf("\t\tDETAILS");
 printf("\n================================================\n");
 printf("Type : %f",ch);
 printf("Price : %f",price);
 printf("Quantity : %f",qu);
 printf("Total price : %f",sum);


 return 0;
}



Was This Post Helpful? 0
  • +
  • -

#10 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 710
  • View blog
  • Posts: 2,033
  • Joined: 20-March 10

Re: error C2082: redefinition of formal parameter 'price'

Posted 29 August 2012 - 10:28 PM

Yes it will have..

you have to be patient change this

03 float calculate (float);
04 float display (float);
to this

float calculate (float ch,float qu,float price);
float display (float ch,float qu,float sum,float price);

This post has been edited by snoopy11: 29 August 2012 - 10:28 PM

Was This Post Helpful? 1
  • +
  • -

#11 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 30 August 2012 - 12:06 AM

now it is work but it doesn't print display

just print like this

http://postimage.org/image/5rlxcfaxp/
Was This Post Helpful? 0
  • +
  • -

#12 NeeZaaR  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 39
  • Joined: 29-August 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 30 August 2012 - 08:53 AM

sorry like this
Posted Image

I need outpt like this
======================================
RNR COFFEE SHOP
======================================
1. Cappuccino [RM2.00]
2. Espresso [RM3.90]
3. Latte [RM2.80]
Enter choice : 1
Enter quantity : 8
======================================
DETAILS
======================================
Type : Cappuccino
Price : RM2.00
Quantity : 8
Total price : RM16.00
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: error C2082: redefinition of formal parameter 'price'

Posted 30 August 2012 - 09:58 AM

Show us your current code with all your new changes. Are you now calling display() with the appropriate parameters?
Was This Post Helpful? 0
  • +
  • -

#14 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 710
  • View blog
  • Posts: 2,033
  • Joined: 20-March 10

Re: error C2082: redefinition of formal parameter 'price'

Posted 30 August 2012 - 10:13 AM

Nope,

He is calling display like this display(sum);

When it should be like this...

display(ch, qu, sum, price);

Try changing line 61 to that.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2082: redefinition of formal parameter 'price'

Posted 30 August 2012 - 10:37 AM

Also you may want to study the links provided in my signature. They should help explain how to use functions.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1