I amm getting 3 errors for , please help..
error C2660: 'calculate_discount' : function does not take 1 arguments
the code is -
-
#include <stdio.h>
-
#include <conio.h>
-
-
int calculate_discount(int,int,int);
-
-
int main()
-
{
-
-
int item1,item2,item3;
-
int price1,price2,price3;
-
-
-
-
/* For reference
-
Item Discount
-
Item 1 20%
-
Item 2 30%
-
Item 3 40%
-
-
*/
-
printf("Enter Price for Item 1: \n");
-
scanf("%d",&item1);
-
printf("Enter Price for Item 2: \n");
-
scanf("%d",&item2);
-
printf("Enter Price for Item 3: \n");
-
scanf("%d",&item3);
-
-
-
printf("Net price of Item 1: %d \n",calculate_discount(item1)); /*ERROR IS HERE*/
-
printf("Net Price of Item 2: %d \n",calculate_discount(item2)); /*ERROR IS HERE*/
-
printf("Net Price of Item 3: %d \n",calculate_discount(item3)); /*ERROR IS HERE*/
-
-
getch();
-
}
-
-
int calculate_discount(int item1,int item2, int item3)
-
-
{
-
-
int price1,price2,price3;
-
-
if(item1)
-
price1=item1-((item1*20)/100);
-
else if(item2)
-
price2=item2-((item2*20)/100);
-
else if (item3)
-
price3=item3-((item2*20)/100);
-
-
return item1,item2,item3;
-
-
}
-
7 3210
This code: - int calculate_discount(int,int,int);
says that calculate_discount needs htree arguments that are ints. You call it like this: - 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. - calculate_discount(item1);
so you would declare your function as: - int calculate_discount(int);
and not: - int calculate_discount(int,int,int);
but that would only allow me to calculate 1 discount value...what about the other 3..should i make seperate items for it
could you please post the error-free solution..as I am new to Pointers
i must use
Function prototype: void calculatediscount(int *, int *, int *)
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: - void calculatediscount(int *, int *, int *)
but you have coded this in your program: - 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.
this is what i have done but the answer is not calculated but instead comes as same as the input... -
-
-
#include <stdio.h>
-
#include <conio.h>
-
-
-
void calculate_discount(int*,int*,int*);
-
-
void main()
-
{
-
-
int item1,item2,item3;
-
-
-
-
-
/* For reference
-
Item Discount
-
Item 1 20%
-
Item 2 30%
-
Item 3 40%
-
-
*/
-
printf("Enter Price for Item 1: \n");
-
scanf("%d",&item1);
-
printf("Enter Price for Item 2: \n");
-
scanf("%d",&item2);
-
printf("Enter Price for Item 3: \n");
-
scanf("%d",&item3);
-
-
-
printf("Net price of Item 1: %d \n",item1);
-
printf("Net Price of Item 2: %d \n",item2);
-
printf("Net Price of Item 3: %d \n",item3);
-
-
getch();
-
}
-
-
void calculate_discount(int *item1,int *item2, int *item3)
-
-
{
-
-
int price1,price2,price3;
-
-
if(item1)
-
price1=*item1-((*item1*20)/100);
-
else if(item2)
-
price2=*item2-((*item2*20)/100);
-
else if (item3)
-
price3=*item3-((*item3*20)/100);
-
-
-
-
}
-
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: - void calculate_discount(int *item1,int *item2, int *item3,
-
int* price1, int* price2, int* price3);
The best solution is: - 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: - 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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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: ...
|
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) ...
|
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...
|
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...
|
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;
|
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>...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |