473,385 Members | 1,983 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,385 software developers and data experts.

cannot convert parameter 1 from 'int *_w64' to 'int'

5
i'm having problems with this portion of code... the entire program is an invoice for a carpet installation asking for the room dimensions and various rates and amounts to calculate how much to charge someone for service. the assignment requires you to pass at least one parameter by reference, which would be in this function. i've tried a ton of different ways to do it but clearly i don't understand the whole function scene because i just can't get it to work and my professor insists it's how i'm passing the parameter. the error with this code says "error c2664: cannot convert parameter 1 from 'int *_w64' to 'int'.

Expand|Select|Wrap|Line Numbers
  1. //declaring functions
  2. int GetLength();
  3. int GetWidth();
  4. int CalculateArea(int Length, int Width);
  5.  
  6.  
  7. int main()
  8. {
  9.     int Length, Width, Area;
  10.  
  11. //print functions
  12.     Length=GetLength();
  13.     Width=GetWidth();
  14.     Area=CalculateArea(&Length, &Width);
  15.  
  16.     return 0;
  17. }
  18.  
  19. //ask user for length, return as int
  20. int GetLength(int &Length)
  21. {
  22.  
  23.         cout << "What is the length of the room?" ;
  24.         cin >> Length;
  25.  
  26.         while (Length <0)
  27.         { cout << "Please enter a positive number." << endl;
  28.         cin >> Length;
  29.         }
  30.  
  31.     return Length;
  32. }
  33.  
  34. //ask user for width, return as int
  35. int GetWidth(int &Width)
  36. {
  37.  
  38.         cout << "What is the width of the room?" ;
  39.         cin >> Width;
  40.  
  41.         while (Width <0)
  42.         { cout << "Please enter a positive number." << endl;
  43.         cin >> Width;
  44.         }
  45.  
  46.  
  47.     return Width;
  48. }
  49.  
  50. int CalculateArea(int Length, int Width)
  51. {
  52.         int Area;
  53.         Area=Length*Width;
  54.  
  55.         return (Area);
  56.  
  57.  
  58. }
Oct 14 '07 #1
7 9991
Ganon11
3,652 Expert 2GB
When you declare your functions, you have them returning an int and accepting no parameters. Look down at your function definitions - they say they are returning an int and accepting an integer by reference. See a problem here?

You don't need the return value if you're going to use pass-by-reference and get the values in the functions. But if you change the program to work this way, you'll need to modify your main() function.
Oct 14 '07 #2
Laharl
849 Expert 512MB
Besides that, when you use the & operator as a prefix operator, like &width, you're actually passing a pointer, because & is the address-of operator. To fix that, when you call the function, remove the &.
Oct 14 '07 #3
mng2nf
5
Besides that, when you use the & operator as a prefix operator, like &width, you're actually passing a pointer, because & is the address-of operator. To fix that, when you call the function, remove the &.


i'm supposed to pass it like that... that's the one my teacher wants passed using the address instead of the variable
Oct 14 '07 #4
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Oct 15 '07 #5
Laharl
849 Expert 512MB
i'm supposed to pass it like that... that's the one my teacher wants passed using the address instead of the variable
With that syntax, you're passing by pointer, not by reference, in which case, in the function definition, change the & to *, so that you are passing pointers rather than &. You will need to dereference the pointers before you can change anything, however.
Oct 15 '07 #6
Ganon11
3,652 Expert 2GB
Ermm....If he has something like

Expand|Select|Wrap|Line Numbers
  1. void getWidth(int& Width)
as a function header, that will work just fine, Laharl. C++ knows that he's passing a pointer, but does all the work behind the scenes to do it, so that he just has to use:

Expand|Select|Wrap|Line Numbers
  1. getWidth(width)
in main. C++ equates this to passing &width, and in the function, dereferences that pointer immediately, so you can treat it like a normal variable.

So there's no need to change the & to a *.
Oct 15 '07 #7
weaknessforcats
9,208 Expert Mod 8TB
but clearly i don't understand the whole function scene
It's quite simple.

Image that you are the function. Your arguments come in the mailbox in the form of letters. One of the letters has a questionaire for you to fill out.

It should be obvious that this is a copy of the original questionaire.

When you return it, you make a copy, put it in an envelope, and mail it.

The questionaire that you received goes into your wastebasket.

This is the simple call by value that is used for variables.

I may happen that you do not receive a questionaire but instead your mail has an envelope with a URL in it. You use the URL to locate the the questionaire an complete it online.

Here the URL is a copy of the URL the sender has. But the URL is not the3 questionaire, rather, it is the address of the questionaire. By using the address you can locate and use the original questionaire.

This is the simple call by value that is used for pointers to variables.

Your original function was:
int CalculateArea(int Length, int Width);
So, you call the function with the variables themselves. A copy is made and the copy shows up in the mail for CalculateArea.

However, your call was:
Area=CalculateArea(&Length, &Width);
and you passed in the addresses of the variables instead of the variables themselves. To do this, your function needs to be set up to receive pointers:
Expand|Select|Wrap|Line Numbers
  1. int CalculateArea(int* Length, int* Width);
  2.  
Oct 15 '07 #8

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

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
1
by: Gary | last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to int... Earlier in my code I was setting up my dataset... I add an int field like so... ...
9
by: Igor Okulist | last post by:
int func(void**); { short* p = NULL; func(&p); //<<< here } Could somebody remind me why is this not allowed ? error message: "cannot convert parameter from 'short **' to 'void **'"
2
by: Seli | last post by:
Hello I have a BusinessClass CreditCardInfo defined in a library: namespace Cockpit.TrackingLibrary { /// <summary> /// Summary description for OPCSignal. /// </summary> public class...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
2
by: nassim.bouayad.agha | last post by:
Hello, here is a code snippet showning my problem : template<typename _K> class TClass1 { public: void Process(const _K& arg) const {
1
by: td0g03 | last post by:
I have no idea why am I getting an error C2664: 'parseInput' : cannot convert parameter 2 from 'main::WORD_STRUCT ' to 'struct WORD_STRUCT ' #include <stdio.h> #include <stdlib.h> #include...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.