Thread: Cannot convert parameter to struct type.

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    34

    Cannot convert parameter to struct type.

    I am trying to make a automated menu. It shows there are no syntax errors but when compiled it says cannot convert choice from type into to menuItemType. I am not sure what I did wrong. Here is the code

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    
    
    
    using namespace std;
    
    
    struct menuItemType
    {
        string menuItem;
        double menuPrice;
        
    };
    
    
    const int NUMBER_OF_ROWS = 8;
    const int NUMBER_OF_COLUMNS = 2;
    
    
    
    
    
    
    double showMenu(menuItemType menuList[NUMBER_OF_ROWS]);
    void getData(menuItemType menuList[NUMBER_OF_ROWS]);
    double printCheck(menuItemType menuList[NUMBER_OF_ROWS]);
    
    
    int main()
    {
        
        menuItemType menuList[NUMBER_OF_ROWS];
        getData(menuList);
        showMenu(menuList);
        
        
        
    }
    
    
    void getData(menuItemType menuList[NUMBER_OF_ROWS])
    {
        
        ifstream inFile;
        inFile.open("C:\\Users\\Dylan\\Documents\\InfileTravischapter9Page629.txt");
        
        for (int i = 0; i < 8; i++)
        {
            inFile >> menuList[i].menuItem
                   >> menuList[i].menuPrice;
        }       
    }
    
    
    double showMenu(menuItemType menuList[NUMBER_OF_ROWS])
    {
        
        getData(menuList);
        int choice;
        bool selectAnother;
        for(int i=0; i < 8; i++)
        { 
        cout << menuList->menuPrice << endl;
        }
        cout << "What would you like to eat, you can have up to one of each item on the menu" << endl;
        cout << "Press the following keys to select your items" << endl;
        cout << "1 = Plain\n2 = Bacon and Egg\n 3 = Muffin\n 4 = French Toast\n 5 = Fruit Basket \n 6 = Cereal \n 7 = Coffee \n 8 = Tea" << endl;
        cin >> choice;
        cout << "Would you like to select another item? Enter yes or no" << endl;
        cin >> selectAnother;
        
        while(selectAnother == true)
        {
        cout << "What would you like to eat, you can have up to one of each item on the menu" << endl;
        cout << "Press the following keys to select your items" << endl;
        cout << "1 = Plain\n2 = Bacon and Egg\n 3 = Muffin\n 4 = French Toast\n 5 = Fruit Basket \n 6 = Cereal \n 7 = Coffee \n 8 = Tea" << endl;
        cin >> choice;
        cout << "Would you like to select another item? Enter yes or no" << endl;
        cin >> selectAnother;
        }
        
        printCheck(choice);
        
        
    
    
        return 0;
    }
    
    
    double printCheck(int choice)
    {
        double bill;
        double price;
        double check;
        
        
        if(choice == 1)
            price = 1.45;
        if(choice == 2)
            price = 2.45;
        if(choice == 3)
            price = .99;
        if(choice == 4)
           price = 1.99;
        if(choice == 5)
            price = 2.49;
        if(choice == 6)
            price = .69;
        if (choice == 7)
            price = .50;
        if(choice == 8)
            price = .75;
    
    
    
    
        bill = bill + price;
        check = bill * .05 + bill;
    
    
        cout << "Your check is $" << check << endl;
        
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Check the type of the parameter of printCheck and the type of the argument that you passed when calling it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    Quote Originally Posted by laserlight View Post
    Check the type of the parameter of printCheck and the type of the argument that you passed when calling it.
    Whoa, whoa, whoa; hold the horses! Somebody used the words argument and parameter correctly!

  4. #4
    Registered User
    Join Date
    Oct 2013
    Posts
    34
    I understand now. I had a variable in my function prototype that i wasn't even using. Okay i got it fixed but now when i run it this happens. My menu is messed up. I tryed to format my menu to pop up like this with a text file but instead of a menu popping up it says the bottom is right. but the top should display a item then the price not a bunch of numbers. then when I select yes to enter another choice it infinite loops. so i will have to fix that to.


    -9.25596e+061
    -9.25596e+061
    -9.25596e+061
    -9.25596e+061
    -9.25596e+061
    -9.25596e+061
    -9.25596e+061
    -9.25596e+061
    What would you like to eat, you can have up to one of each item on the menu
    Press the following keys to select your items
    1 = Plain
    2 = Bacon and Egg
    3 = Muffin
    4 = French Toast
    5 = Fruit Basket
    6 = Cereal
    7 = Coffee
    8 = Tea

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It displays a bunch of numbers because you wrote the code do print the menu prices.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Oct 2013
    Posts
    34
    I am trying to output the whole menu but now im getting 1 error C2676: binary '[' : 'menuItemType' does not define this operator or a conversion to a type acceptable to the predefined operator
    here is the method im trying
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <iomanip>
    
    
    
    
    using namespace std;
    
    
    struct menuItemType
    {
    	string menuItem;
    	double menuPrice;
    	
    };
    
    
    const int NUMBER_OF_ROWS = 8;
    const int NUMBER_OF_COLUMNS = 2;
    
    
    
    
    
    
    double showMenu(menuItemType menuList[NUMBER_OF_ROWS]);
    void getData(menuItemType menuList[NUMBER_OF_ROWS]);
    double printCheck(double choice);
    
    
    int main()
    {
    	
    	menuItemType menuList[NUMBER_OF_ROWS];
    	getData(menuList);
    	showMenu(menuList);
    	
    	
    	
    }
    
    
    void getData(menuItemType menuList[NUMBER_OF_ROWS])
    {
    	
    	ifstream inFile;
    	inFile.open("C:\\Users\\Dylan\\Documents\\InfileTravischapter9Page629.txt");
    	
    	for (int i = 0; i < 8; i++)
    	{
    		for(int j=0; j<2; j++) //This loops on the columns
    		{
    		inFile >> menuList[i].menuItem
    			   >> menuList[j].menuPrice;
    	
    		}
    	}
    }
    
    
    double showMenu(menuItemType menuList[NUMBER_OF_ROWS])
    {
    	
    	getData(menuList);
    	double choice;
    	bool selectAnother;
    	for(int i=0; i<8; i++)   
    	{
    		for(int j=0; j<2; j++) 
    		{
    			cout << menuList[i][];
    		}
    		cout << endl;
    	}

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    "cout << menuList[i][]" -- even if you had something in the last set of braces, menuList is still only a one-dimensional array.

  8. #8
    Registered User
    Join Date
    Oct 2013
    Posts
    34
    am i getting any closer? The program now runs but it dosen't output the menu right still. It just gives me a bunch of random numbers that aren't even in the .txt file.




    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <iomanip>
    
    
    
    
    using namespace std;
    
    
    struct menuItemType
    {
    	string menuItem;
    	double menuPrice;
    	
    };
    
    
    const int NUMBER_OF_ROWS = 8;
    const int NUMBER_OF_COLUMNS = 2;
    
    
    
    
    
    
    double showMenu(menuItemType menuList[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]);
    void getData(menuItemType menuList[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]);
    double printCheck(double choice);
    
    
    int main()
    {
    	
    	menuItemType menuList[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS];
    	getData(menuList);
    	showMenu(menuList);
    	
    	
    	
    }
    
    
    void getData(menuItemType menuList[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS])
    {
         
        ifstream inFile;
        inFile.open("C:\\Users\\Dylan\\Documents\\InfileTravischapter9Page629.txt");
         
        for (int i = 0; i < 8; i++)
        {
            for(int j=0; j<2; j++) //This loops on the columns
            {
            inFile >> menuList[i][j].menuItem
                   >> menuList[i][j].menuPrice;
         
            }
        }
    }
     
    
    
    double showMenu(menuItemType menuList[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS])
    {
         
        getData(menuList);
        double choice;
        bool selectAnother;
        for(int i=0; i<8; i++)   
        {
            for(int j=0; j<2; j++) 
            {
                cout << menuList[i][j].menuItem;
    			cout << menuList[i][j].menuPrice;
            }
          
        }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-22-2010, 09:05 PM
  2. Cannot convert parameter
    By (++ in forum Windows Programming
    Replies: 6
    Last Post: 01-12-2010, 01:36 AM
  3. cannor convert parameter...
    By SpEkTrE in forum C Programming
    Replies: 17
    Last Post: 02-18-2005, 03:39 AM
  4. ERROR! cannot convert parameter...
    By watshamacalit in forum C Programming
    Replies: 14
    Last Post: 09-09-2003, 01:11 PM
  5. Cannot convert parameter 1 from......
    By endo in forum C++ Programming
    Replies: 9
    Last Post: 10-28-2002, 05:05 PM