| | |
cannot convert from 'double' to 'float [6][3]'
![]() |
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Solved Threads: 0
Using this code:
Fees = ovrh + (wr * z);
I am getting the following error:
error C2440: '=' : cannot convert from 'double' to 'float [6][3]'
Fees, ovrhd, wr and z are all declared as float. I believe if I can figure out what the problem is, I will have a functioning program. After several days straight of this program, I believe that I may be forgetting something basic.
Fees = ovrh + (wr * z);
I am getting the following error:
error C2440: '=' : cannot convert from 'double' to 'float [6][3]'
Fees, ovrhd, wr and z are all declared as float. I believe if I can figure out what the problem is, I will have a functioning program. After several days straight of this program, I believe that I may be forgetting something basic.
Could you show more of the code? Specifically the actual declarations for the variables would be helpful. I find no such issue with this minimal code sample.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main(void) { float ovrh = 1.0F, wr = 1.0F, z = 1.0F, Fees = ovrh + (wr * z); printf("Fees = %g\n", Fees); return 0; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Slight nitpick:
Those aren't two floats (1.0 and 2.0), they're two doubles.
•
•
•
•
Originally Posted by Chainsaw
The calculation of two floats yields a double.
C Syntax (Toggle Plain Text)
fees = 1.0 * 2.0;
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Solved Threads: 0
The purpose of the program is to store shipping costs in an array and then display them on the screen, in a formatted output.
Here are the declarations:
float Fees [6][3];
float i, j;
int wr, z;
const double ovrh = 2.27; // I tried to enter this as a const float, but the compiler didn't like it, so I changed it to a double which solved that one problem.
The assignment is 4 days late, so I am going to just turn it in as it. I would still like to see it work though. Thank you so much for your help!
Here are the declarations:
float Fees [6][3];
float i, j;
int wr, z;
const double ovrh = 2.27; // I tried to enter this as a const float, but the compiler didn't like it, so I changed it to a double which solved that one problem.
The assignment is 4 days late, so I am going to just turn it in as it. I would still like to see it work though. Thank you so much for your help!
•
•
•
•
Originally Posted by Dave Sinkula
Could you show more of the code? Specifically the actual declarations for the variables would be helpful. I find no such issue with this minimal code sample.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main(void) { float ovrh = 1.0F, wr = 1.0F, z = 1.0F, Fees = ovrh + (wr * z); printf("Fees = %g\n", Fees); return 0; }
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Solved Threads: 0
The purpose of the program is to store shipping costs in an array and then display them on the screen, in a formatted output.
Here are the declarations:
float Fees [6][3];
float i, j;
int wr, z;
const double ovrh = 2.27; // I tried to enter this as a const float, but the compiler didn't like it, so I changed it to a double which solved that one problem.
The assignment is 4 days late, so I am going to just turn it in as it. Thank you so much for your help!
Here are the declarations:
float Fees [6][3];
float i, j;
int wr, z;
const double ovrh = 2.27; // I tried to enter this as a const float, but the compiler didn't like it, so I changed it to a double which solved that one problem.
The assignment is 4 days late, so I am going to just turn it in as it. Thank you so much for your help!
•
•
•
•
Originally Posted by Chainsaw
The calculation of two floats yields a double. Compilers often WARN about converting from double to float because of a possible loss of precision.
YOUR error code sure sounds like you have an ARRAY of floats like
float fees[6][3];
fees = 1.0 * 2.0; // error double to float [6][3]
Aha! So your original statement was not entirely accurate. Fees is declared as an array of an array of float -- this is not the same and your compiler was kindly informing you of this. A single float might be Fees[0][0]. Try this (I'm assuming i and j are loop indices -- except that then they must be integral types and not floating point, but I'm used to i and j as loop indices -- and this is inside these loops.
•
•
•
•
Fees, ovrhd, wr and z are all declared as float.
C Syntax (Toggle Plain Text)
Fees[i][j] = ovrh + (wr * z);
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Ah HAH! As I suspected.
Dave, you are right that '1.0' is a double. However, I still believe that two floats used in a calculation result in a double, in the same way that two chars used in a calculation result in an int. In any case, the compiler can deal with that and generally puts out a warning, not an error.
Dave, you are right that '1.0' is a double. However, I still believe that two floats used in a calculation result in a double, in the same way that two chars used in a calculation result in an int. In any case, the compiler can deal with that and generally puts out a warning, not an error.
•
•
•
•
Originally Posted by Chainsaw
Ah HAH! As I suspected.
Dave, you are right that '1.0' is a double. However, I still believe that two floats used in a calculation result in a double, in the same way that two chars used in a calculation result in an int. In any case, the compiler can deal with that and generally puts out a warning, not an error.
const double ovrh = 2.27; "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Oops. I didn't read the comment. It makes me curious -- tnorton: are you saying that the compiler barked about something like this? But the other stuff about the promotions should be correct.
•
•
•
•
// I tried to enter this as a const float, but the compiler didn't like it, so I changed it to a double which solved that one problem
C Syntax (Toggle Plain Text)
const float ovrh = 2.27F;
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: Commission or Brokerage Problem
- Next Thread: Linking errors of socket functions
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






