473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Error c2660 in C programming

11
I amm getting 3 errors for , please help..

error C2660: 'calculate_discount' : function does not take 1 arguments

the code is

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5. int calculate_discount(int,int,int);
  6.  
  7. int main()
  8. {
  9.  
  10.     int item1,item2,item3;
  11.     int price1,price2,price3;
  12.  
  13.  
  14.  
  15.     /* For reference
  16.         Item    Discount
  17.         Item 1     20%
  18.         Item 2     30%
  19.         Item 3    40% 
  20.  
  21.     */
  22.         printf("Enter Price for Item 1: \n");
  23.         scanf("%d",&item1);
  24.         printf("Enter Price for Item 2: \n");
  25.         scanf("%d",&item2);
  26.         printf("Enter Price for Item 3: \n");
  27.         scanf("%d",&item3);
  28.  
  29.  
  30.         printf("Net price of Item 1: %d \n",calculate_discount(item1)); /*ERROR IS HERE*/    
  31.         printf("Net Price of Item 2: %d \n",calculate_discount(item2)); /*ERROR IS HERE*/
  32.         printf("Net Price of Item 3: %d \n",calculate_discount(item3)); /*ERROR IS HERE*/
  33.  
  34.         getch();
  35. }
  36.  
  37. int calculate_discount(int item1,int item2, int item3)
  38.  
  39. {
  40.  
  41.     int price1,price2,price3;
  42.  
  43.     if(item1)
  44.         price1=item1-((item1*20)/100);
  45.     else if(item2)
  46.         price2=item2-((item2*20)/100);
  47.     else if (item3)
  48.         price3=item3-((item2*20)/100);
  49.  
  50.     return item1,item2,item3;
  51.  
  52. }
  53.  
Mar 5 '12 #1
7 3210
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. int calculate_discount(int,int,int);
says that calculate_discount needs htree arguments that are ints. You call it like this:

Expand|Select|Wrap|Line Numbers
  1. calculate_discount(3,4,6);
You are only using one argument. Hence the error.

You may have a design issue. With three items you would call calculate_discount using one the one item whose discount is needed.

Expand|Select|Wrap|Line Numbers
  1. calculate_discount(item1);
so you would declare your function as:
Expand|Select|Wrap|Line Numbers
  1. int calculate_discount(int);
and not:
Expand|Select|Wrap|Line Numbers
  1. int calculate_discount(int,int,int);
Mar 5 '12 #2
Bil M
11
but that would only allow me to calculate 1 discount value...what about the other 3..should i make seperate items for it
Mar 5 '12 #3
Bil M
11
could you please post the error-free solution..as I am new to Pointers
Mar 5 '12 #4
Bil M
11
i must use
Function prototype: void calculatediscount(int *, int *, int *)
Mar 5 '12 #5
weaknessforcats
9,208 Expert Mod 8TB
As it stands now, your code won't compile.
In addition to your reported problem, the calculate_discount function is attempting to return 3 its. No dice. A function may return a type or a pointer to a type and that's it. Only one value.

Now you say you must use:
Expand|Select|Wrap|Line Numbers
  1. void calculatediscount(int *, int *, int *)
but you have coded this in your program:
Expand|Select|Wrap|Line Numbers
  1. int calculate_discount(int,int,int);
Do you see any difference?
The one in your program won't work for you but the one you must use will.
Isuggest you code the correct function in your program and then post again if you are still stuck.
Mar 5 '12 #6
Bil M
11
this is what i have done but the answer is not calculated but instead comes as same as the input...

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6.  
  7. void calculate_discount(int*,int*,int*);
  8.  
  9. void main()
  10. {
  11.  
  12.     int item1,item2,item3;
  13.  
  14.  
  15.  
  16.  
  17.     /* For reference
  18.         Item    Discount
  19.         Item 1     20%
  20.         Item 2     30%
  21.         Item 3    40% 
  22.  
  23.     */
  24.         printf("Enter Price for Item 1: \n");
  25.         scanf("%d",&item1);
  26.         printf("Enter Price for Item 2: \n");
  27.         scanf("%d",&item2);
  28.         printf("Enter Price for Item 3: \n");
  29.         scanf("%d",&item3);
  30.  
  31.  
  32.         printf("Net price of Item 1: %d \n",item1);    
  33.         printf("Net Price of Item 2: %d \n",item2);
  34.         printf("Net Price of Item 3: %d \n",item3);
  35.  
  36.         getch();
  37. }
  38.  
  39. void calculate_discount(int *item1,int *item2, int *item3)
  40.  
  41. {
  42.  
  43.     int price1,price2,price3;
  44.  
  45.     if(item1)
  46.         price1=*item1-((*item1*20)/100);
  47.     else if(item2)
  48.         price2=*item2-((*item2*20)/100);
  49.     else if (item3)
  50.         price3=*item3-((*item3*20)/100);
  51.  
  52.  
  53.  
  54. }
  55.  
Mar 6 '12 #7
weaknessforcats
9,208 Expert Mod 8TB
Your function calculates price1, price2 and price3 but these are local variables inside the function and they are destroyed when the function completes. You have to do something to get the results passed out of the function.

You could have three more arguments for that:
Expand|Select|Wrap|Line Numbers
  1. void calculate_discount(int *item1,int *item2, int *item3,
  2.  int* price1, int* price2, int* price3);
The best solution is:
Expand|Select|Wrap|Line Numbers
  1. int calculate_discount(int item);
where you call the function with one of the items and it returns the discount price for that item. Then you can call it using each item and get the discount price for that item.

However, you said you had to use:
Expand|Select|Wrap|Line Numbers
  1. void calculatediscount(int *, int *, int *)
where there is no way to get the discount price back from the function. I guess you could display it inside the function but that is a very poor design choice since you don't generally want screen displays spattered throughout the code as that leads to a very complicated user interface control.
Mar 6 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public ICustomTypeDescriptor { private: ...
3
by: raveneros | last post by:
error C2660: 'checkF' : function does not take 1 parameters this is the error. void checkF(char s,char dStr) { for (int i=0; i<count; ++i) if (strcmp(s, list.getId())==0) ...
1
by: Minx | last post by:
This seems like a cool site, I wish I could have found this sooner. Can someone pls help me with this line of code? I get an error C2660 telling me the function does not take an argument ( The...
1
by: izzy79 | last post by:
Hi, I'm trying to error trap an append query, if the record already exists in the table. I'm not sure why the error message ("Rule already exisits") pops up regardless if that record is in the...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
6
by: RedRuffing15 | last post by:
Hey, Im getting two C2660 Errors even though I have defined all my variables and such, and Im not sure why it isnt working, can anyone help me out? //Program Project 5 #include<iostream>...
1
by: denxx | last post by:
Hi, I am new in C++ and was trying to run a programme where I found an error using the pow statement. Error showed is error C2660: 'pow' : function does not take 1 parameters. As I have a square on...
10
by: charmeda103 | last post by:
My program keeps getting me and error and i dont why here is the error message error C2061: syntax error: identifier 'infile' error C2660: 'ReadDate' : function does not take 6 arguments...
3
by: AccessBeetle | last post by:
I have a form which asks user his/her username and password. If the username does not exists it prompts you a message saying "Please enter a valid username." The weired part is, there are several...
2
by: Richard Ballin | last post by:
Hello All, I am taking a class using Visual Studio C++ Express 2010 and on one of the first projects i need to use the Math::Pow() function. The book does not do a good job of explaining how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.