I am using Visual C++ 2005 to write code a win32 console application.
There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function.
The statement is:
tempDistance += pow((data[selectedInstance][k]-data[j][k...
I used various headers like:
%26lt;cmath%26gt;, %26lt;math.h%26gt; %26lt;valarray%26gt; and %26lt;complex%26gt; but the error message remained the same.
What is the cause of the error? I've checked the syntax and it seems correct.
Pow() error in Visual C++ 2005?
double pow(double x,double y) (from math.h); there you also have powf (for float) and powl ofr long double); Check how you declared tempDistance and the array! The compiler doesn't know what conversion to apply in your case...
Reply:What?
Reply:Double check the data type of your argument to the pow() function. There is likely more than one overload of pow() that will do what you want, but the compiler can't decide which one to use. Just stick and explicit cast in there and be done with it. To wit:
pow( double(data[selectedInstance]........
Note the insertion of a double() constructor!
Or use old-fashioned C-style cast:
(double)(arg)
Reply:Here is what I'm finding as the problem, pow(int, int) has been removed from math.h.
1. Look at the data type of your arguments.
2. Look at the data type of your variable. (tempDistance)
The compiler is trying to figure it what to use when it just can't.
if you haven't written overloaded functions yet the error might not make much sense to you.
(Remember that pow(int,int) is gone. )
flash cards
Tuesday, July 14, 2009
Switch/case statement in C help please?
The problem is make a program that will display a corresponding letter grade to the ff. input values: A for 90 above, B for 80-89, C for 70-79, D for 60-69, and F for below 60 using switch/case statements.
The limits for A are 90%26lt;=A%26lt;=100; for 50%26lt;=F%26lt;=59. The default statement is "out of range". How do you input the syntax for the cases, complete with the %26lt;= and %26gt;= conditions? Just one example of a case (to follow and continue) will be great, thanks.
Switch/case statement in C help please?
in cases, we can't use %26lt;= or %26gt;=
one way to solve ur problem wud be:
void main()
{
int num,A,B,C,D,F;
printf("Enter a number: ");
scanf("%d",%26amp;num);
switch(A)
{
case 90:
case 91:
/*
..
.. u can fill the values in between..
*/
case 100: printf("grade is A"); break;
case 80:
case 81:
/*
..
.. fill the in between values
*/
case 89: printf("grade is B"); break;
/* similarly for other grades.. just remember to put break; statement on the last value of a given range for a grade */
default: printf("The number is out of range");
}
Reply:You need to use if/else statement. Switch won't allow that type of checking.
The limits for A are 90%26lt;=A%26lt;=100; for 50%26lt;=F%26lt;=59. The default statement is "out of range". How do you input the syntax for the cases, complete with the %26lt;= and %26gt;= conditions? Just one example of a case (to follow and continue) will be great, thanks.
Switch/case statement in C help please?
in cases, we can't use %26lt;= or %26gt;=
one way to solve ur problem wud be:
void main()
{
int num,A,B,C,D,F;
printf("Enter a number: ");
scanf("%d",%26amp;num);
switch(A)
{
case 90:
case 91:
/*
..
.. u can fill the values in between..
*/
case 100: printf("grade is A"); break;
case 80:
case 81:
/*
..
.. fill the in between values
*/
case 89: printf("grade is B"); break;
/* similarly for other grades.. just remember to put break; statement on the last value of a given range for a grade */
default: printf("The number is out of range");
}
Reply:You need to use if/else statement. Switch won't allow that type of checking.
Switch/case problem in C language. Help please?
Problem: Write a program that accepts an ordinary number and output its equivalent Roman numeral. The ordinary numbers and their equivalent Roman numerals are as follows: 1 corresponds to I ; 5 = V; 10 = X; 50 = L; 100 = C; 500 = D; 1000 = M.
Sample input/output on screen: Enter a number: 2968
The Roman numeral is: MMCMLXVIII
Note that maximum input number is 3,000.
I don't know how to do it, it can't possibly mean doing the syntax 3000 times! I think it may have to do with the place values, but I don't know how to work it out. Help please? Thanks.
Switch/case problem in C language. Help please?
To convert an integer into Roman numerals, you'll need to have a "while loop" to repeatedly generate the numerals you want until the result reaches zero.
Inside the loop, you'll have a switch statement that goes something like:
Switch input:
case input %26gt; 1000
output "M"
input = input - 1000
break
case input %26gt; 900
output "XM"
input = input - 900
break
...
...
End Switch
Reply:From old memories.. look at the dragon book for compilers. I vaguely recall it having this case as an example for illustrating scanning or parsing.
read from left to right. for every letter that represents a value greater than the most recent one that you have read in, subtract the smaller one from the bigger one. At the same time, if you come across an X, add 10 to some variable. If you read IX, add 1 to a variable and remember 1 in a temp variable. if the temp is lesser than the next one, say in this case, X(=10), then subtract the temp from the grand total, and add present-temp to the grand total. This way, you should be able to work out.
Anyway, this came to me off handed and might need some fine tuning.
Reply:Pseudo-code sample could be something like:
char input[];
char output[];
int number;
for(i=0;i%26lt;sizeof(input)/sizeof(char);i...
number = atoi(input[i]);
switch(number)
case 1:
if(number%1000) output[i]="M";
else(number%100) output[i]="C";
else(number%10) output[i]="X";
else output[i]="I";
break;
}
But you'll need to extend this and write it out properly, cos I couldn't be bothered ;-)
Reply:No need for a switch statement at all. The Cleanest that I can think of would be this:
void PrintRoman (int Number)
{
char Roman[100];
int Position = 0;
while (Number %26gt;= 1000)
{
Roman[Position++] = 'M';
Number -= 1000;
}
if (Number %26gt;= 900)
{
Roman[Position++] = 'C';
Roman[Position++] = 'M';
Number -= 900;
}
if (Number %26gt;= 500)
{
Roman[Position++] = 'D';
Number -= 500;
}
while (Number %26gt;= 100)
{
Roman[Position++] = 'C';
Number -= 100;
}
if (Number %26gt;= 90)
{
Roman[Position++] = 'X';
Roman[Position++] = 'C';
Number -= 90;
}
if (Number %26gt;= 50)
{
Roman[Position++] = 'L';
Number -= 50;
}
while (Number %26gt;= 10)
{
Roman[Position++] = 'X';
Number -= 10;
}
if (Number %26gt;= 9)
{
Roman[Position++] = 'I';
Roman[Position++] = 'X';
Number -= 9;
}
if (Number %26gt;= 5)
{
Roman[Position++] = 'V';
Number -= 5;
}
if (Number %26gt;= 4)
{
Roman[Position++] = 'I';
Roman[Position++] = 'V';
Number -= 4;
}
while (Number %26gt;= 1)
{
Roman[Position++] = 'I';
Number -= 1;
}
Roman[Position] = '\0';
printf ("Roman is %s\n", Roman)
}
There are more compact ways to write this using either parallel arrays or a structure, but for clarity, the above is best.
flower girl
Sample input/output on screen: Enter a number: 2968
The Roman numeral is: MMCMLXVIII
Note that maximum input number is 3,000.
I don't know how to do it, it can't possibly mean doing the syntax 3000 times! I think it may have to do with the place values, but I don't know how to work it out. Help please? Thanks.
Switch/case problem in C language. Help please?
To convert an integer into Roman numerals, you'll need to have a "while loop" to repeatedly generate the numerals you want until the result reaches zero.
Inside the loop, you'll have a switch statement that goes something like:
Switch input:
case input %26gt; 1000
output "M"
input = input - 1000
break
case input %26gt; 900
output "XM"
input = input - 900
break
...
...
End Switch
Reply:From old memories.. look at the dragon book for compilers. I vaguely recall it having this case as an example for illustrating scanning or parsing.
read from left to right. for every letter that represents a value greater than the most recent one that you have read in, subtract the smaller one from the bigger one. At the same time, if you come across an X, add 10 to some variable. If you read IX, add 1 to a variable and remember 1 in a temp variable. if the temp is lesser than the next one, say in this case, X(=10), then subtract the temp from the grand total, and add present-temp to the grand total. This way, you should be able to work out.
Anyway, this came to me off handed and might need some fine tuning.
Reply:Pseudo-code sample could be something like:
char input[];
char output[];
int number;
for(i=0;i%26lt;sizeof(input)/sizeof(char);i...
number = atoi(input[i]);
switch(number)
case 1:
if(number%1000) output[i]="M";
else(number%100) output[i]="C";
else(number%10) output[i]="X";
else output[i]="I";
break;
}
But you'll need to extend this and write it out properly, cos I couldn't be bothered ;-)
Reply:No need for a switch statement at all. The Cleanest that I can think of would be this:
void PrintRoman (int Number)
{
char Roman[100];
int Position = 0;
while (Number %26gt;= 1000)
{
Roman[Position++] = 'M';
Number -= 1000;
}
if (Number %26gt;= 900)
{
Roman[Position++] = 'C';
Roman[Position++] = 'M';
Number -= 900;
}
if (Number %26gt;= 500)
{
Roman[Position++] = 'D';
Number -= 500;
}
while (Number %26gt;= 100)
{
Roman[Position++] = 'C';
Number -= 100;
}
if (Number %26gt;= 90)
{
Roman[Position++] = 'X';
Roman[Position++] = 'C';
Number -= 90;
}
if (Number %26gt;= 50)
{
Roman[Position++] = 'L';
Number -= 50;
}
while (Number %26gt;= 10)
{
Roman[Position++] = 'X';
Number -= 10;
}
if (Number %26gt;= 9)
{
Roman[Position++] = 'I';
Roman[Position++] = 'X';
Number -= 9;
}
if (Number %26gt;= 5)
{
Roman[Position++] = 'V';
Number -= 5;
}
if (Number %26gt;= 4)
{
Roman[Position++] = 'I';
Roman[Position++] = 'V';
Number -= 4;
}
while (Number %26gt;= 1)
{
Roman[Position++] = 'I';
Number -= 1;
}
Roman[Position] = '\0';
printf ("Roman is %s\n", Roman)
}
There are more compact ways to write this using either parallel arrays or a structure, but for clarity, the above is best.
flower girl
Query format for date incorrect using C#?
This query results in a syntax error. The error message makes mention of a missing operator, but I think it is a format problem with the date. I've searched the internet and all of my books and there is very little information on how to properly format a date/time query in Visual C Sharp.
This is the query that contains an error.
NOTE: I HAD TO ADD SPACES IN ORDER TO VIEW THE CODE HERE.
"SELECT DateTime FROM Events WHERE " + monthCalendar1. SelectionStart. AddDays(4). ToString() + " %26lt; DateTime"
Ive tried using "BETWEEN "+ monthCalendar1. SelectionStart. AddDays(4). ToString() +" AND DateTime"
but had the same error
there must be a problem with the format of monthCalendar1. SelectionStart. AddDays(4). ToString()
I hope there are some knowledgeable C# programmers out there with experience working with databases!
Query format for date incorrect using C#?
1) You have not specified the field in the where clause
"SELECT DateTime FROM Events WHERE FIELDNAME BETWEEN " + monthCalendar1. what ever
2) When you are using date values and passing to Sql, you need to format it
example: SELECT * FROM example WHERE exampledate between '2007-01-01'
AND '2007-06-10'
This is the query that contains an error.
NOTE: I HAD TO ADD SPACES IN ORDER TO VIEW THE CODE HERE.
"SELECT DateTime FROM Events WHERE " + monthCalendar1. SelectionStart. AddDays(4). ToString() + " %26lt; DateTime"
Ive tried using "BETWEEN "+ monthCalendar1. SelectionStart. AddDays(4). ToString() +" AND DateTime"
but had the same error
there must be a problem with the format of monthCalendar1. SelectionStart. AddDays(4). ToString()
I hope there are some knowledgeable C# programmers out there with experience working with databases!
Query format for date incorrect using C#?
1) You have not specified the field in the where clause
"SELECT DateTime FROM Events WHERE FIELDNAME BETWEEN " + monthCalendar1. what ever
2) When you are using date values and passing to Sql, you need to format it
example: SELECT * FROM example WHERE exampledate between '2007-01-01'
AND '2007-06-10'
Lowercase to Uppercase C++ program?
Can someone create a C++ program for me that will convert lowercase letters to uppercase letters and will stop when the user inputs a non-lowercase character? I'd like it to be simple and only use iostream as the header file. Please, no if statements, just a while loops, cout, cin, endl, and proper syntax. Thnx!
Lowercase to Uppercase C++ program?
use toupper,tolower,isalpha functions
Reply:What for? C has built-in funtions do that.
Reply:I'll let you do your own homework, but I'll give you a hint. A character is really just an int. The mapping of characters to their numeric ASCII values is well defined. Capital A=65, B=66, all the way to Z=90. Lower case letters are a=97 to z=122. Converting a lowercase letter to its uppercase counterpart can be simply a matter of subtraction.
Here's a link to an ascii chart, but I'm sure your text book has one. http://www.asciitable.com/
Lowercase to Uppercase C++ program?
use toupper,tolower,isalpha functions
Reply:What for? C has built-in funtions do that.
Reply:I'll let you do your own homework, but I'll give you a hint. A character is really just an int. The mapping of characters to their numeric ASCII values is well defined. Capital A=65, B=66, all the way to Z=90. Lower case letters are a=97 to z=122. Converting a lowercase letter to its uppercase counterpart can be simply a matter of subtraction.
Here's a link to an ascii chart, but I'm sure your text book has one. http://www.asciitable.com/
AS/400 and C++ :::for video game developement which is best?
I am getting to go to school for developing video games. I have heard a great deal about C++, but not much about AS/400. I have read all about it AS/400 in Wikopedia. When I did a search for video game development employment, I read that many are asking for this language. Can someone tell me if I had to learn only one which one should I learn and why? If I could learn both, which one should I base my emphasis in? I did notice that they are different in structure and syntax so learning one will not benefit the other too much other than in concept of ideas.
Thanks
AS/400 and C++ :::for video game developement which is best?
While C is native on the AS/400, this is not a gaming system but rather a business batch job processing and DBMS system primarily used for medium to large scale data storage and manipulation like data warehousing and ERP applications.
It is good to learn how to logically think so you can apply logic to any programming language. Once you are able to break a large problem down into smaller pieces, you are well on your way to being a programmer. Remember, LOGIC will NEVER change, only the syntax will.......
If you are looking for game programming, the AS/400 is not where you should be looking.
Reply:The AS/400 is an IBM midrange computer (a small step down from a mainframe). It is not a complier. They are probably referring to C++ on an AS/400.
Thanks
AS/400 and C++ :::for video game developement which is best?
While C is native on the AS/400, this is not a gaming system but rather a business batch job processing and DBMS system primarily used for medium to large scale data storage and manipulation like data warehousing and ERP applications.
It is good to learn how to logically think so you can apply logic to any programming language. Once you are able to break a large problem down into smaller pieces, you are well on your way to being a programmer. Remember, LOGIC will NEVER change, only the syntax will.......
If you are looking for game programming, the AS/400 is not where you should be looking.
Reply:The AS/400 is an IBM midrange computer (a small step down from a mainframe). It is not a complier. They are probably referring to C++ on an AS/400.
Write a c program to store and edit the records?
for eg.if i give"create table tablename(name,varchar(10),salary,(10,2)... program should parse the given statement and check if the syntax is correct.if it is correct,then a structure should be created with the same tablename with name and salary in it.i am just a beginner so dont go deeply into sql or anything.i need a c program just to parse and check a given statement.only the statement is similar to that in sql.like this i have to do for select,insert,delete and update.
Write a c program to store and edit the records?
Best option would be to use LEX and YACC to parse the ddl statements. Then you could use a flat file (with your predefined formats for your name/salary fields) to populate the objects.
The scope for coding is beyond the means of this group. I guess you have a good starting point though.
curse of the golden flower
Write a c program to store and edit the records?
Best option would be to use LEX and YACC to parse the ddl statements. Then you could use a flat file (with your predefined formats for your name/salary fields) to populate the objects.
The scope for coding is beyond the means of this group. I guess you have a good starting point though.
curse of the golden flower
Subscribe to:
Posts (Atom)