getting an error, need help

This is a discussion on getting an error, need help within the C++ Programming forums, part of the General Programming Boards category; hello, i keep getting this error in my c++ program: incompatible types of assignment of ' const char[2]' to 'char[20]' ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    20

    getting an error, need help

    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???

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    I'm pretty sure what the problem is, just post your code so we can show you how to fix it...
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    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<"----------------------------------------------"
    }

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Code:
    // 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)
    // edit: you also forgot alot of ;'s towards the end of your code
    Last edited by face_master; 11-21-2002 at 11:32 PM.
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    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?

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    your code was pretty crazy, but I made some fixes here and there but you might want fix it some more
    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;
    }
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  7. #7
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    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?
    Probably becuase of all of the missing ;'s or something...

    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
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    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...

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    hey face master how do u make the code u wrote print the actual receipt? it doesnt seem to want to do that

  10. #10
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> 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
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  11. #11
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> 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...
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  12. #12
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Your program is really screwed. I need to go now but i'll try fixing it later
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  13. #13
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    ok thanks

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    20
    do u know how to fix it?

  15. #15
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,867
    Hmm, take a look at the if's and else's
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21