Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c++ help? won't compile correctly?

It won't compile correctly

Its supposed to ask the user for a four digit code with two uppercase letters as its first two digits and the next two must be a sum of 10 or less.

// Assignment 4 problem 1

// Programmed by: Jonathan Kurtz

#include <iostream>

using namespace std;

char *getEmployeeID(char [], int);

int main()

{

const int SIZE = 5;

char employee[SIZE];

getEmployeeID(employee, SIZE);

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

cout << employee[i];

cout << endl;

system("pause");

return 0;

}

char *getEmployeeID(char arr[], int size)

{

char *pointer;

pointer = arr;

bool status = true;

do

{

cout << "Enter a valid employee ID: ";

cin.getline(arr, size);

for (int count = 0; count < 2; count++)

{

if (!isupper(arr[count]))

status = false;

else

status = true;

}

int numb1 = arr[2] - '0';

int numb2 = arr[3] - '0';

int numb3 = numb1 + numb2;

if (numb3 > 10)

status = false;

else

status = true;

} while (status != tue);

return pointer;

}

1 Answer

Relevance
  • 7 years ago

    for (int count = 0; count < 2; count++)

    {

    if (!isupper(arr[count]))

    status = false;

    else

    status = true;

    }

    // Eddie is right on this part but also,

    // the result of thestatement above is being overwritten down here

    if (numb3 > 10)

    status = false;

    else

    status = true;

    // consider using the value of status to determine whether or not the rest of the code in the

    // while loop should be executed

Still have questions? Get your answers by asking now.