#include <string>
#include <vector>
#include <iomanip>
#include <istream>
#include <fstream>
#include "...\myUtils.cpp"
void inputCases(string[], vector<double>);
void inputPrice(string[], vector<double>);
void displayReport(string[], vector<double>, vector<double>);
using namespace std;

int main()
{
    double tmpCases, tmpPayRate;
               
    vector <double> cases;
    vector <double> payRates;
    
    ofstream file;
    file.open("salsaCase.txt");
           
    string tmpName[5];
    tmpName[0]="Mild";
    tmpName[1]="Medium";
    tmpName[2]="Sweet";
    tmpName[3]="Hot";
    tmpName[4]="Zesty";   
    char mans=0; 
   
     do
     {//menu
      cout<<"1. Input Price\n";
      cout<<"2. Input Cases Sold\n";
      cout<<"3. Display Report\n";
      cout<<"4. Quit\n";
      
      cin>>mans;
      while (mans <1 || mans > 4)
      {
            cout <<"Please enter a valid menu choice(1-4)\n";
            cin>>mans;
            }
      if (mans !=4)
      {//guts of menu
      switch (mans)
      {
             case 1:
                  void inputPrice(string tmpName[], vector<double> payRates);
                  break;
             case 2:
                  void inputCases(string tmpName[], vector<double> cases);
                  break;
             case 3:
                  void displayReport(string tmpName[], vector<double> payRates, vector<double> cases);
                  break;
         }
         if (mans == 4)
         exit(0);
         }
         }

         //function definitions
         //input price per case
         //ERROR happens right below here
          void inputPrice (string tmpName[] ,vector<double> payRates)
         {
              for(int i=0;i<5;i++)
              {
              cout<<"Enter price for one case of "<< tmpName[i] <<": ";
              cin >> tmpPayRate;
              payRates.push_back(tmpPayRate);
              cin.ignore();
             pause();
              }
         }
  //input number of cases
              void inputCases(string tmpName[] ,vector<double> cases)
              {
               for(int i=0;i<5;i++)
              {
             cout << "Enter # of cases of "<< tmpName[i] <<" salsa : ";
             cin >> tmpCases;
             cases.push_back(tmpCases);
             cin.ignore();
             pause();
             } 
             }//show sales   
            int displayReport(string tmpName[], vector<double> payRates, vector<double> cases)
             {
             cout<< setprecision(2)<<fixed<<showpoint;
             file<< setprecision(2)<<fixed<<showpoint;   
     
    cout<<setw(20) << left << "  Names"
        <<setw(10) << right<< "Hours"
        <<setw(10) << "Price"
        <<setw(15) <<"GrossPay\n";
        
    file<<setw(20) << left << "  Name"
        <<setw(10) << right<< "Hours"
        <<setw(10) << "Price"
        <<setw(15) <<"GrossPay\n";
        
    for(int i=0;i<cases.size();i++)
    {   
        //loop for generating salsa case lists
            double grossPay =cases[i]*payRates[i];
            cout<<setw(20) << left << tmpName[i]
        <<setw(10) << right << cases[i]
        <<setw(10) << payRates[i]
        <<setw(15) << grossPay <<"\n";
        
            file<<setw(20) << left << tmpName[i]
        <<setw(10) << right << cases[i]
        <<setw(10) << payRates[i]
        <<setw(15) << grossPay <<"\n";
        file.flush();
        pause();
    }
    }
    
    
    
    file.close();
    pause("\n\n\nPress a key to terminate...");
    exit(0);
    
   
}

using DevC++ only because my teacher says so
following is compiler error codes

E:\COP2\classNotes\1stdraft.cpp: In function `int main()':
E:\COP2\classNotes\1stdraft.cpp:66: error: expected `while' before "inputPrice"
E:\COP2\classNotes\1stdraft.cpp:66: error: expected `(' before "inputPrice"
E:\COP2\classNotes\1stdraft.cpp:66: error: expected primary-expression before "tmpName"
E:\COP2\classNotes\1stdraft.cpp:66: error: expected primary-expression before "payRates"
E:\COP2\classNotes\1stdraft.cpp:67: error: expected `)' before '{' token
E:\COP2\classNotes\1stdraft.cpp:67: error: expected `;' before '{' token

E:\COP2\classNotes\1stdraft.cpp:79: error: a function-definition is not allowed here before '{' token
E:\COP2\classNotes\1stdraft.cpp:79: error: expected `,' or `;' before '{' token
E:\COP2\classNotes\1stdraft.cpp:90: error: a function-definition is not allowed here before '{' token
E:\COP2\classNotes\1stdraft.cpp:90: error: expected `,' or `;' before '{' token

Execution terminated

Dani AI

Generated

Good news: the scary error is really just a parsing cascade. The compiler saw a do { ... } but never found the matching while (...) ;, so when it reached your first statement after the block it expected the while and instead saw inputPrice. That matches what hinted at with the misplaced brace. Close the do loop properly (or replace the outer do loop with a simple while(true)/for(;;)), then recompile to see the next set of real errors.

In the switch you are declaring functions, not calling them. Drop the types and void when you invoke them:

switch (mans) {
  case 1: inputPrice(tmpName, payRates); break;
  case 2: inputCases(tmpName, cases);    break;
  case 3: displayReport(tmpName, payRates, cases); break;
}

A few must-fixes that will otherwise keep it from compiling or working:

  • Make signatures match. Your prototype says void displayReport(...) but the definition returns int. Pick one (void is fine) and use it consistently.
  • Do not define functions inside main. Ensure the closing } for main appears before any function definitions. ’s advice to format your code makes this easy to spot.
  • Pass vectors by reference if you want push_back to persist, and do not rely on tmpCases, tmpPayRate, or file from main inside helpers. Either make them local or pass them in.
void inputPrice(const string names[], vector<double>& payRates);
void inputCases(const string names[], vector<double>& cases);
void displayReport(const string names[], const vector<double>& payRates,
                   const vector<double>& cases /*, std::ostream& out */);
  • Use int mans (or compare a char to '1'..'4'), and validate input in a loop.
  • Prefer including a header (myUtils.h) instead of a .cpp, as ’s bracket note suggests larger structural cleanups.

Recommended Answers

All 3 Replies

You might have missed a bracket somewhere... Only such a mistake causes so many insignificant errors.

You might have missed a bracket somewhere... Only such a mistake causes so many insignificant errors.

And to find it, format your code properly. It's your first debugging tool.

do
     {//menu
      cout<<"1. Input Price\n";
      cout<<"2. Input Cases Sold\n";
      cout<<"3. Display Report\n";
      cout<<"4. Quit\n";
      
      cin>>mans;
      } // missed this one
      while (mans <1 || mans > 4)
commented: Why can't you let him find it? It's his project. -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.