unable to locate the errors (maybe trouble with arrays)

This is a discussion on unable to locate the errors (maybe trouble with arrays) within the C++ Programming forums, part of the General Programming Boards category; I'm writing a program that reads in data from an input file and then in the report module it is ...

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

    unable to locate the errors (maybe trouble with arrays)

    I'm writing a program that reads in data from an input file and then in the report module it is supposed to ask the user to type in the item it wants to look up and display all of the information stored for that item on the screen. I am receiving the following error messages:

    c:\my documents\c++\project_2.cpp(120) : error C2143: syntax error : missing ')' before ';'
    c:\my documents\c++\project_2.cpp(120) : warning C4552: '<' : operator has no effect; expected operator with side-effect
    c:\my documents\c++\project_2.cpp(120) : error C2059: syntax error : ')'
    c:\my documents\c++\project_2.cpp(121) : error C2143: syntax error : missing ';' before '{'


    All of the errors are in the report module in the section that is blue.
    Code:
    #include<iostream>
    #include<String>
    #include <ios>
    #include <fstream>
    using namespace std;
    
    void printMenu(int &selection);
    void startSystem();
    void login();
    void modify();
    void report();
    void exitSystem();
    
    int count=0;
    string inventory[50];
    string item[50];
    string vendor_name[50];
    double vendor_price[50];
    double retail_price[50];
    int number[50];
    
    int main()
    {
     int selection;
    
     startSystem();
    
     //menu
     printMenu(selection);
     while(selection !=4)
     {
    
     if (selection==1)
      login();
     else if (selection==2)
      modify();
     else if (selection==3)
      report();
     else if (selection==4)
      exitSystem();
     else
      cout<<"You entered and invalid number.";
     printMenu(selection);
     }
     
     return 0;
    }
    
    void printMenu(int &selection)
    {
     system("cls");
     cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
     cout<<"   Acme Department Store Inventory System"<<endl<<endl;
     cout<<"    1.  Log into System"<<endl;
     cout<<"    2.  Modify Inventory"<<endl;
     cout<<"    3.  Report Section"<<endl;
     cout<<"    4.  Exit the system"<<endl;
     cout<<endl;
    
     cout<<"       What would you like to do? ";
     cin>>selection;
     
    }
    
    void startSystem()
    {
     ifstream input;
    
     input.open("invent.dat");
     while (!input.eof())
     {
      input>>inventory[count]>>item[count]>>vendor_name[count]>>vendor_price[count]>>retail_price[count]>>number[count];
      cout<<"The inventory number is "<<inventory<<endl;
      cout<<"The item name is "<<item<<endl;
      cout<<"The vendor name is "<<vendor_name<<endl;
      cout<<"The vendor price is "<<vendor_price<<endl;
      cout<<"The retail price is "<<retail_price<<endl;
      cout<<"The number in stock is "<<number<<endl;
      count=count+1;
     }
     input.close();
    }
    void login()
    {
     cout<<"In login"<<endl;
     system ("pause");
    }
    
    void modify()
    {
     cout<<"In modify"<<endl;
     system ("pause");
    }
    
    void report()
    {
     int choice, i;
     string num, department;
     ifstream input; 
    
     //report menu
     system("cls");
     cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
     cout<<"    Report Menu"<<endl;
     cout<<"    ==========="<<endl;
     cout<<"    1. Report by inventory item"<<endl;
     cout<<"    2. Report by Department"<<endl;
     cout<<"    3. Report by Vendor"<<endl;
     cout<<"    4. All items in stock"<<endl;
     cout<<"    5. Exit Report Menu"<<endl;
     cout<<endl;
     cout<<"    What would you like to do?";
     cin>>choice;
     
      if (choice==1)
     {
      cout<<"Enter the inventory number ";
      cin>>num;
    
      while(i = 0; i < count; i++)
      {
       if(num==inventory[i])
       {
        cout<<inventory[i]<<" "<<item[i]<<" "<<vendor_name[i]<<" "<<vendor_price[i]<<" "<<retail_price[i]<<" "<<number[i]<<endl;
        system("pause");
       }
       else
       {
        cout<<"There is no such item in inventory"<<endl;
        system("pause");
       }
      }
     }
    }
    void exitSystem()
    {
     ofstream output;
     
     output.open("invent.dat");
     output<<inventory<<" "<<item<<" "<<vendor_name<<" "<<vendor_price<<" "<<retail_price<<" "<<number<<endl;
     output.close();
    }

    &#91;code]&#91;/code]tagged by Salem
    You made it all so pretty, yet forgot the most important ones to make the code readable...

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I'm not going to count the rows in your code, you could at least mark those rows with red (120 and 121).

    <edit>
    I see it's fixed. Exactly which row is 120? The top blue one?
    </edit>

    c:\my documents\c++\project_2.cpp(120) : error C2143: syntax error : missing ')' before ';'
    Obviously, you missed one paranthesis. Count them and see where one's missing. I hope you're indenting your code, which makes it really easy to spot these errors.

    c:\my documents\c++\project_2.cpp(120) : warning C4552: '<' : operator has no effect; expected operator with side-effect
    Perhaps you printed cout < "Hi" somewhere?

    c:\my documents\c++\project_2.cpp(120) : error C2059: syntax error : ')'
    Probably a follow-up from your earlier errors.

    c:\my documents\c++\project_2.cpp(121) : error C2143: syntax error : missing ';' before '{'
    You missed a semicolon ( ; ) somewhere.

    And please use codetags ( [CODE] insert code here [/CODE] ) in the future, as it makes the code more readable.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Thank you Salem

    Thank you so much. You were exactly right. All I did was change the while to a for. I can't believe it was as simple as that, I would have never found it. Thank You

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having Trouble Passing typedef Arrays to a Function
    By jlharrison in forum C Programming
    Replies: 1
    Last Post: 03-27-2006, 12:06 PM
  2. Errors i'm having trouble fixing :\
    By yaniv89 in forum Windows Programming
    Replies: 5
    Last Post: 08-26-2005, 03:35 PM
  3. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 03:34 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors with arrays and structures
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 11:48 PM

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