Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ C2146 Syntax error I am getting a syntax error: missing ';' before identifier 'cout' at line 51. My code was working fine and then

C++ C2146 Syntax error

I am getting a syntax error: missing ';' before identifier 'cout' at line 51. My code was working fine and then I realized I had forgotten to have the year displayed. Once I entered that then I got the error message at line 51. I have double checked and I have a ; at the end of that line so I am puzzled and would like some assistance. I have identified the line in question with a comment.

#include

#include

#include

using namespace std;

int findW(char[], int);

long getCustNum(char[], int);

int getYear(char str[], int start);

int main()

{

int strLength, wPointer;

long custNumber;

char workOrderNumber[6];

int year;

char workOrder[15] = "91800w940770";

while (true)

{

cout << "Enter a three part work order code in the format CustomerNumber Year OrderNumber : " << endl;

cout << "The first 5 - 6 digits contain the work order number digits before the w" << endl;

cout << "The 2 digits following the w represent the year" << endl;

cout << "For example 91800w940770 " << endl;

cout << "Enter work order code (type Quit to stop): ";

cin >> workOrder;

if (strcmp(workOrder, "Quit") == 0) //if user types Quit, then program will close.

break;

strLength = strlen(workOrder);

wPointer = findW(workOrder, strLength);

custNumber = getCustNum(workOrder, wPointer);

year = getYear(workOrder, wPointer + 1);

strcpy_s(workOrderNumber, workOrder + wPointer + 3);

cout << "Length " << strLength << endl;

cout << "Location of w =" << wPointer << endl;

cout << "Customer number = " << custNumber << endl;

cout << "Year of order = " << year << endl;

cout << "Order number = " << workOrderNumber << endl; //This is the line number that is being identified with the syntax error.

system("pause");

}

return 0;

}

int findW(char str[], int len)

{

for (int i = 0; i < len; i++)

{

if (str[i] == 'w')

return i;

}

return -1;

}

long getCustNum(char str[], int wIndex)

{

char cnum[7];

strncpy_s(cnum, str, wIndex);

return atol(cnum);

}

int getYear(char str[], int start)

{

char year[3];

strncpy_s(year, str + start, 2);

return atoi(year);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions