Jul 7, 2011 at 10:24pm UTC
I'm trying to copy out this program, which illustrates a use of char type.
#include <iostream>
using namespace std;
int main()
{
char letter;
for(letter= "A"; letter <= "Z"; letter++)
cout<< letter;
return 0;
}
My compiler gives the error- Invalid conversion from "const char*" to "char", and the error- ISO C++ forbids comparison between pointer and integer.
Can somebody explain these errors?
Jul 7, 2011 at 10:45pm UTC
Your error is referring to the assignment, and the condition within your for loop. When assigning, or comparing a character to a char type, you must specify the character within single quotes, like this: char Char = 'a' .
Wazzak
Last edited on Jul 7, 2011 at 10:45pm UTC
Jul 10, 2011 at 9:10pm UTC
Im having trouble with this: (char),(name) it says "name" is undefined??
#include <iostream>
using namespace std;
int main()
{
//program code
//declared then initialized
float nums[3];
nums[0] = 1.5; nums[1] = 2.27; nums[2] = 3.25
//declared and initialized
char name[5] = {'m','i','k','e','\0'};
int coords[2][3] = {{1,2,3},{4,5,6}};
//insert statements
cout << "nums[0]:" << nums[0] << endl;
cout << "nums[1]:" << nums[1] << endl;
cout << "nums[2]:" << nums[2] << endl;
cout << "name[0]:" << name [0] << endl;
cout << "Text string:" << name << endl;
cout << "coords[0][2]:" << coords[0][2] << endl;
cout << "coords[1][2]:" << coords[1][2] << endl;
getchar();
return 0;
}
this should be right, but it doesn't work. what am i doing wrong?
Last edited on Jul 10, 2011 at 9:17pm UTC
Jul 10, 2011 at 9:32pm UTC
Wow! your absolutely right. thank you for your reply. My compiler told me i was missing that (;), but didnt say where. I thought i had everything in place, i was wrong. thanks again, you're super.