hello, i keep getting this error in my c++ program: incompatible types of assignment of ' const char[2]' to 'char[20]'
what does this mean???
Printable View
hello, i keep getting this error in my c++ program: incompatible types of assignment of ' const char[2]' to 'char[20]'
what does this mean???
I'm pretty sure what the problem is, just post your code so we can show you how to fix it...
This is the code, its for a school assignment
Code:#include <iostream.h>
#include<string>
int main()
{
char manager[20];
char product1 [20];
float price1;
char product2 [20];
float price2;
char product3 [20];
float price3;
char product4 [20];
float price4;
char product5 [20];
float price5;
char date [20];
char storelocation [20];
char x;
float Total;
cout<<"Enter the location of the woolworths store";
cin>> storelocation;
cout<<"Enter the date of purchases";
cin>> date;
cout<<"Enter the store manager's name";
cin>> manager;
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product1;
cout<<"Enter the price of the product";
cin>> price2;
if (product1 = "x")
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product2;
cout<<"Enter the price of the product";
cin>> price2;
if (product2 = "0")
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product3;
cout<<"Enter the price of the product";
cin>> price3;
if (product3 = "0")
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product4;
cout<<"Enter the price of the product";
cin>> price4;
if (product4 = "0")
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product5;
cout<<"Enter the price of the product";
cin>> price5;
if (product5 = "0")
cout<< "Thanks, press enter to receive a receipt";
Total = (price1 + price2 + price3 + price4 + price5)
cout<<" PROUDLY AUSTRALIAN "
cout<<" WOOLWORTHS "
cout<<" ABN 88 000 014 675 "
cout<<" The Fresh Food People "
cout<<" Mona Vale Ph: 9997-4777 "
cout<<" YOUR STORE MANAGER IS:" <<manager
cout<<" $. "
cout<<" ------- "
cout<<" " <<product1 <<price1
cout<<" " if (product2 > "z") <<product2 <<price2
cout<<" " if (product3 > "z") <<product3 <<price3
cout<<" " if (product4 > "z") <<product4 <<price4
cout<<" " if (product5 > "z") <<product5 <<price5
cout<<" 5 TOTAL " <<Total
cout<<" E.F.T " <<Total
cout<"----------------------------------------------"
}
// edit: you also forgot alot of ;'s towards the end of your codeCode:// lines like this are illegal
if (product1 = "x")
// use the strcmp function in strings.h to compare strings for equality like so...
if (strcmp(product1, "x") == 0)
thanks a lot for that face master, it seemed to do the trick!
however i still have one error which i cant solve (im a doofus)
it says: parse error before '<' on line 65 which is the cout<<" PROUDLY AUSTRALIAN " line.
can u plz tell me whats wrong?
your code was pretty crazy, but I made some fixes here and there but you might want fix it some more :p
Code:#include <iostream.h>
#include<string>
int main()
{
char manager[20];
char product1 [20];
float price1 = 0;
char product2 [20];
float price2 = 0;
char product3 [20];
float price3 = 0;
char product4 [20];
float price4 = 0;
char product5 [20];
float price5 = 0;
char date [20];
char storelocation [20];
float Total;
cout<<"Enter the location of the woolworths store";
cin>> storelocation;
cout<<"Enter the date of purchases";
cin>> date;
cout<<"Enter the store manager's name";
cin>> manager;
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product1;
cout<<"Enter the price of the product";
cin>> price2;
if (strcmp(product1, "x") == 0)
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product2;
cout<<"Enter the price of the product";
cin>> price2;
if (strcmp(product2, "0") == 0)
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product3;
cout<<"Enter the price of the product";
cin>> price3;
if (strcmp(product3, "0") == 0)
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product4;
cout<<"Enter the price of the product";
cin>> price4;
if (strcmp(product4, "0") == 0)
cout<< "Thanks, press enter to receive a receipt";
else
cout<<"Enter the product and weight, if finished type '0' in";
cin>> product5;
cout<<"Enter the price of the product";
cin>> price5;
if (strcmp(product5, "0") == 0)
cout<< "Thanks, press enter to receive a receipt";
Total = (price1 + price2 + price3 + price4 + price5);
cout<<" PROUDLY AUSTRALIAN \n";
cout<<" WOOLWORTHS \n";
cout<<" ABN 88 000 014 675 \n";
cout<<" The Fresh Food People \n";
cout<<" Mona Vale Ph: 9997-4777 \n";
cout<<" YOUR STORE MANAGER IS:" <<manager << "\n";
cout<<" $. \n";
cout<<" ------- \n";
cout<<" \n";
cout<<product1;
cout<<price1;
cout<<" \n";
if (product2 > "z") { cout <<product2; cout <<price2; }
cout<<" \n";
if (product3 > "z") { cout<<product3; cout<<price3; }
cout<<" \n";
if (product4 > "z") { cout<<product4; cout<<price4; }
cout<<" \n";
if (product5 > "z") { cout<<product5; cout<<price5; }
cout<<" 5 TOTAL " <<Total;
cout<<" E.F.T " <<Total;
cout<<"----------------------------------------------";
return 0;
}
Probably becuase of all of the missing ;'s or something...Quote:
Originally posted by holoduke
thanks a lot for that face master, it seemed to do the trick!
however i still have one error which i cant solve (im a doofus)
it says: parse error before '<' on line 65 which is the cout<<" PROUDLY AUSTRALIAN " line.
can u plz tell me whats wrong?
Lol, I wok at a woolworths - it sucks. I do like no work so they dont like me. Only work some weekends, though so its ok. I'm 15 by the way
thank you so much! you are a 15 yr old genius!
im 15yrs old and i cant understand c++, but ive only been learning it for 2 weeks.
Woolies keeps rejecting my applications... :mad:
hey face master how do u make the code u wrote print the actual receipt? it doesnt seem to want to do that
>> Woolies keeps rejecting my applications...
Serious? Lol. It was easy for me. Somehow I got the job. I tried for a job @ hoyts couple weeks ago, but they knocked me back. I work on a checkout but thats becuase you do the least work :D
>> hey face master how do u make the code u wrote print the actual receipt? it doesnt seem to want to do that
Yeh thats pretty weird how it just stops. I'll have a go at it now...
Your program is really screwed. I need to go now but i'll try fixing it later
ok thanks
do u know how to fix it?
Hmm, take a look at the if's and else's
i cant find anything wrong with the if statements?
yeah, it is fine, except it cant print out the actual receipt which is what the program was intended to do. i cant seem to work out how to do it either
Hey, just noticed - what's this supposed to do?
It somehow doesn't look right to me... I could be wrong though.Code:if(product1 > "z") {...}
that if statement just means that if someone has written more than just "z" for the product details, that it should display those details, otherwise leave it blank. its basically a test, im not sure if its the best way of doing it though. if u can help me with it, i would really appreciate it.
Somebody correct me if I'm wrong, but this is what I'm thinking it will do:
take the value of the pointer called product1
compare it to
the value of a pointer to a static array of 1 character, which is "z"
So basically, it's not really comparing the strings, but the pointers (which are sort of like integers, unless I'm wrong which is very likely). Try something like this:
That might work better, I haven't tried it though.Code:char product[20] = {0}; // or = ""; (I'm not sure)
(...)
if(product[0] != '\0') {...}
that too :)
thanks a lot for that help salem, but when u press "0" to stop typing in products it doesnt display the receipt it just exits
do u know how to fix this?
excuse my dumbness but im not sure where to insert the pause code in the program
Right after the receipt is printed out. Because right after that the program quits; if you pause between that and the quit, it will display then quit after the pause. Otherwise, if you put it earlier, it will pause then display it too fast for you to see and then quit.
wow that works beautifully, thanks alot salem and hunter2
ill be sure to come to u if i have any more problems :D
No problem :)
face_master: Any day!
:p heh
lol, forgot bout this thread :rolleyes: I spend too much time in the General Forum!