3 Replies - 417 Views - Last Post: 18 April 2013 - 08:17 PM Rate Topic: -----

#1 cbrign9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 13

I have an error code saying expected `while' before ( token ?

Posted 18 April 2013 - 02:18 PM

The error code is 163: error: expected `while' before ‘(’ token


#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>

using namespace std;

const int MAX_CUSTOMERS = 1000;
const double OVER_DRAFT = 35.00;


void openAccount(string acno, string fName, string lName, char midInit,
double initBal, string acNums[], string fNames[], string lNames[],
char midInitials[], double balances[], int& numAccs)
{
	acNums[numAccs] = acno;
	lNames[numAccs] = lName;
	fNames[numAccs] = fName;
	midInitials[numAccs] = midInit;
	balances[numAccs] = initBal;
	numAccs++;
}

int linearSearch(string acno, const string acNums[], int numAccs)
{
	int i;
		for (i=0; i<numAccs; i++)
		{
			if (acno == acNums[i])
				return i;
		}
		return -1;
}

void deposit(string acno, double amount, const string acNums[],
double balances[], int numAccs)
{
	int row = linearSearch(acno, acNums, numAccs);
	balances[row] = balances[row] + amount;
}
void menu ()
{
	cout<< "Geaux Tigers Bank ATM"<<endl;
	cout<< "========================="<<endl;
	cout<< "OPEN AN ACCOUNT.......[1]"<<endl;
	cout<< "CLOSE AN ACCOUNT......[2]"<<endl;
	cout<< "DEPOSIT...............[3]"<<endl;
	cout<< "WITHDRAW..............[4]"<<endl;
	cout<< "BALANCE INQUIRY.......[5]"<<endl;
	cout<< "CUSTOMERS LISTING.....[6]"<<endl;
	cout<< "EXIT..................[0]"<<endl;
}



int main()
{
	string acNums[MAX_CUSTOMERS], fNames[MAX_CUSTOMERS], lNames[MAX_CUSTOMERS];
	char midInitials[MAX_CUSTOMERS];
	double balances[MAX_CUSTOMERS];
	
	string acno, lName, fName;
	double initBal, amount;
	char midInit;
	
	int numAccs = 0, pos, option;
	fstream acInfoIn, acInfoOut;
	
	acInfoIn.open("acinfo.dbf", ios::in);
	numAccs = 0;
	while (acInfoIn >> acNums[numAccs])
	{
		acInfoIn>>lNames[numAccs]>>fNames[numAccs]>>midInitials[numAccs]>>balances[numAccs];
		numAccs ++;
	}
	acInfoIn.close();
	
	
	do
	{
		menu();
		cout<<endl;
		cout<< "Select an option->";
		cin>> option;
		cout<<endl;
		switch(option)
		{
			case 1:
					cout<<"Enter a 10-character long account number->";
					cin>> acno;
					if (acno.length() != 10)
					{
						cout<<acno<<" must be 10-character long."<<endl;
					}
					else if (linearSearch(acno, acNums,numAccs) > 0)
					{
						cout<<acno<<" cannot be assigned to multiple customers."<<endl;
					}
					else
					{
						cout<<"Customer's first name ->";
						cin>>fName;
						cout<<"Customer's middle initial ->";
						cin>>midInit;
						cout<<"Customer's last name ->";
						cin>>lName;
						cout<<"Initial Deposit ->";
						cin>>initBal;
						if (initBal < 25.00)
						{
							cout<<" The initial balance required for a new account must be at least $25.00."<<endl;
						}
						else
						{
							openAccount(acno,fName,lName,midInit,initBal,acNums,fNames,lNames,midInitials,balances,numAccs);
						}
					}
					break;
			case 2:
				break;
			case 3:
				cout<<"Enter a 10-character long account number->";
                cin>>acno;
				if (acno.length() != 10)
				{
				   cout<<acno<<" must be 10-character long."<<endl;
				}
				else if (linearSearch(acno,acNums,numAccs) < 0)
				{
				   cout<<acno<<" is not a valid account ."<<endl;
				}
				else
				{
				   cout<<"Enter the amount to be deposited-> ";
				   cin>>amount;
				   if (amount <= 0)
				      cout<<"The amount to be deposited must be at least a penny."<<endl;
				   else
				      deposit(acno,amount,acNums,balances,numAccs);
                }				   
                break;
            case 4:
            	break;
            case 5:
            	break;
            case 6:
            	break;
            case 0:
            	break;
			default:
				cout<<"Invalid menu option."<<endl;
				
		}
	}
	return(0);
}



I know I haven't finished the program but I was trying to compile just to see if it worked and it didnt so
I thought it was the brackets and the end of the program but that didnt work. Need help?

This post has been edited by Martyr2: 18 April 2013 - 02:34 PM
Reason for edit:: Please use code tags in the future, thanks! :)


Is This A Good Question/Topic? 0
  • +

Replies To: I have an error code saying expected `while' before ( token ?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4359
  • View blog
  • Posts: 12,176
  • Joined: 18-April 07

Re: I have an error code saying expected `while' before ( token ?

Posted 18 April 2013 - 02:36 PM

You realize that you have a "do" without the while at the end right? look at line 79, there is the do, where is your while statement at the end of the body? Perhaps around line 154 you need some kind of while condition?

PS. You might want to include <string> if you are going to use the string keyword. :)

This post has been edited by Martyr2: 18 April 2013 - 02:40 PM

Was This Post Helpful? 0
  • +
  • -

#3 cbrign9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 13

Re: I have an error code saying expected `while' before ( token ?

Posted 18 April 2013 - 02:41 PM

Thanks I cant believe I forgot to finish my do-while loop thanks alot
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,268
  • Joined: 05-May 12

Re: I have an error code saying expected `while' before ( token ?

Posted 18 April 2013 - 08:17 PM

I was under the impression that that code was template code given to students as a starting point for a program. I didn't realize you guys had to "write it from scratch". It's amazing how all the variable names are coming out to be the same...
http://www.dreaminco...r-search-error/
http://www.cplusplus...beginner/55739/
http://www.cplusplus.../general/70689/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1