Simple Question? Conversion Error.

G

GRoll21

In this program, it is going to change a value in the array. So to give
it it's new value I need to assign it the new value. It doesn't like
the conversion. Here is the error.

c:\C++\Serendipity\Chapter 9\invmenu.cpp(185): error C2440: '=' :
cannot convert from 'char' to 'char [14]'

Here is the code.

cout <<"\n\nEnter the first letter of the category you would like to
edit: ";
cin >> change;

if (change == 'I' || change =='i')
{
cout << "\nEnter the new ISBN number: ";
cin >> xisbn[14];
isbn[index] = xisbn[14];
cout << "\nThe isbn is now " << isbn[index];
}

cin gets the letter they input for what category they want to change.
then they have to enter the new isbn number and i want it to assign
that number to the array so its saved. but i keep getting that error.

If someone can point me on the right direction or why it doesn't like
that conversion, that would be great! Thank you very much!
 
A

Artie Gold

GRoll21 said:
In this program, it is going to change a value in the array. So to give
it it's its
new value I need to assign it the new value. It doesn't like
the conversion. Here is the error.

c:\C++\Serendipity\Chapter 9\invmenu.cpp(185): error C2440: '=' :
cannot convert from 'char' to 'char [14]'

Here is the code.

cout <<"\n\nEnter the first letter of the category you would like to
edit: ";
cin >> change;

if (change == 'I' || change =='i')
{
cout << "\nEnter the new ISBN number: ";
cin >> xisbn[14];
isbn[index] = xisbn[14];
cout << "\nThe isbn is now " << isbn[index];
}

cin gets the letter they input for what category they want to change.
then they have to enter the new isbn number and i want it to assign
that number to the array so its saved. but i keep getting that error.

If someone can point me on the right direction or why it doesn't like
that conversion, that would be great! Thank you very much!
You have not provided enough context. What is the declaration of `isbn'?
What is the declaration of `xisbn'?

In general, you will be best served by providing *real* code, a minimal
compilable (or something you think *should* be compilable) snippet.

HTH,
--ag
 
G

GRoll21

this is the whole function.

void editBook(int a)
{

///////used to hold new values///
char xisbn[14];
char xtitle[51];
char xauthor[51];
char xpublisher[31];
char xdate[11];
int xqty;
float xwholeSale;
float xretail;
/////////////////////////////////

char change;
char lookUp[51];
bool found = false;

system("cls");
cout << "\n\t\tEnter the title of the book you wish to edit ";
cin >> lookUp;
cout <<"\n\n";

for(int index = 0; index < 20 && !found; index++)
{;

// toupper
char up1[51], up2[51];
for(int position=0; position < 51; position++)
{
up1[position] = toupper(lookUp[position]);
up2[position] = toupper(bookTitle[index][position]);
}
if (strcmp(up1, up2) == 0)
{
found = true;
bookinfo(isbn[index], bookTitle[index], author[index],
publisher[index], dateAdded[index], qtyOnHand[index], wholesale[index],
retail[index]);
}

cout <<"\n\nEnter the first letter of the category you would like to
edit: ";
cin >> change;

if (change == 'I' || change =='i')
{ cin.ignore();
cout << "\nEnter the new ISBN number: ";
cin.getline(xisbn,14);
isbn[index] = xisbn[14];
cout << "\nThe isbn is now " << isbn[index];
cout <<"\n" << xisbn; //test
}
if (change == 'T' || change =='t')
{
}
if (change == 'A' || change =='a')
{
}
if (change == 'P' || change =='p')
{
}
if (change == 'D' || change =='d')
{
}
if (change == 'Q' || change =='q')
{
}
if (change == 'W' || change =='w')
{
}
if (change == 'R' || change =='r')
{
}
}

if(!found)
{
cout << "Book not in Inventory";
}
}
 
V

Victor Bazarov

GRoll21 said:
this is the whole function.

And which line the error is on?

Learn to post correctly, please. I managed to guess where the error
would be, but next time simply put a comment on the same line.
void editBook(int a)
{

///////used to hold new values///
char xisbn[14]; [...]
isbn[index] = xisbn[14]; [...]
}

The posted code does not show what 'isbn' is, so no telling about the
assignment being correct. If 'isbn[index]' is, in fact, a pointer to
char, then you cannot assign a char to a pointer to char. There is
also another bad mistake here: an attempt to extract a value from
a location _beyond_ the array bounds. 'xisbn' is an array of 14 chars
and its elements are numbered from 0 to 13. There _is_no_ char at
location 'xisbn[14]'.

Perhaps what you're trying to accomplish is to copy the contents of
the 'xisbn' array into 'isbn[index]' array, then you need to use

strcpy(isbn[index], xisbn);

(if 'isbn[index]' does in fact point to large enough memory block to
contain the characters), however, if I were to do the same thing in
my own program, I'd probably used 'std::string' to keep both 'isbn'
elements and 'xisbn'. IOW

std::string xisbn;

and then the assignment should simply be

isbn[index] = xisbn;

Good luck!

V
 
G

GRoll21

sorry i don't come here that much for help so i did not understand how
to correctly post. I now know. and yeah that was the error.. doing the
copy worked just fine.

strcpy(isbn[index], xisbn);

thank you very much for helping.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top