By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,484 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,484 IT Pros & Developers. It's quick & easy.

Cannot convert from char[20][40] to char*

P: n/a
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}

Nov 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"GRoll35" <mi**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
Pick an element. cin.getline(bookTitle[index], 40); is probably what you
meant.
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}

Nov 22 '05 #2

P: n/a

"Jim Langston" <ta*******@rocketmail.com> wrote in message
news:KP***************@fe02.lga...
"GRoll35" <mi**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
Pick an element. cin.getline(bookTitle[index], 40); is probably what you
meant.


er, I think it has to be cin.getline(&bookTitle[index], 40);
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}


Nov 22 '05 #3

P: n/a
thanks Jim. That fixed that error now I get all these.. I'm guessing
they are all connected to the same thing..

ser6 fatal error LNK1120: 2 unresolved externals
ser6 error LNK2001: unresolved external symbol "char (* dateAdded)[10]"
(?dateAdded@@3PAY09DA)
ser6 error LNK2001: unresolved external symbol "char (* dateAdded)[10]"
(?dateAdded@@3PAY09DA)
ser6 error LNK2001: unresolved external symbol "char (* bookTitle)[40]"
(?bookTitle@@3PAY0CI@DA)
ser6 error LNK2001: unresolved external symbol "char (* bookTitle)[40]"
(?bookTitle@@3PAY0CI@DA)

im playing around with it to see what it could be.. any idea?

Nov 22 '05 #4

P: n/a
GRoll35 wrote:
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;
Don't declare variables until you need them, and then declare them in
as small a scope as possible. You never use "quant", and "tax" should
be const.

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
Global variables?! Try passing parameters to your function instead.


do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipity Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//
Try:

cin.getline( bookTitle[index], 40 );
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipity Booksellers\n\n";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\tTitle\t\t\t\tPrice\t\tTotal\n";

cout<<"___________________________________________ _____________________________________\n";
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n\n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}


Cheers! --M

Nov 22 '05 #5

P: n/a
Jim Langston <ta*******@rocketmail.com> wrote:
"Jim Langston" <ta*******@rocketmail.com> wrote in message

"GRoll35" <mi**********@gmail.com> wrote in message
extern char bookTitle[20][40]; cin.getline(bookTitle, 40); //****this is the line it doesnt
like*****//


Pick an element. cin.getline(bookTitle[index], 40); is probably
what you meant.


er, I think it has to be cin.getline(&bookTitle[index], 40);


Well, if bookTitle[index] really does not work (tho I think it
should), then &bookTitle[index][0] would be correct for sure.

regards
--
jb

(reply address in rot13, unscramble first)
Nov 22 '05 #6

P: n/a
i added the & like you said Jim.. that fixes all them errors now I'm
left with just this one..

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char (*__w64 )[40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]

Nov 22 '05 #7

P: n/a
GRoll35 wrote:
i added the & like you said Jim.. that fixes all them errors now I'm
left with just this one..

(42): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt
&std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)' :
cannot convert parameter 1 from 'char (*__w64 )[40]' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]


Quote the code you have now. I'm guessing that you have

int cashier(char bookTitle[20][40])
{
....
cin.getline(bookTitle, 40);

but of course I could be wrong.

To solve this yourself remember that bookTitle is an array of titles, so
to input a title you have to say which title in the array of titles
you are trying to input, i.e.

cin.getline(bookTitle[index], 40);

or something.

john
Nov 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.