Hello again to good ol' DaniWeb. Again I'm stuck. I'm a newbie when it comes to C++. I was given an assignment (ATTACHED), which I'm having problems with in the first part of Menu Choice A section. I'm only that far, and haven't proceeded further. I've coded the following (with some of the future code empty, but placed so I can know my basic structure):

/** This program calculates the weekly salaries of 4 employees 
and accumulates non-paid time **/
#include <iostream>
#include <iomanip>
int main()
{
// variables
int input_loop = 0;
int hours[4][5] = {{8,9,11,8,10},
{12,7,12,11,12},
{8,9,10,9,6},
{8,7,8,6,6}}; // array to store hours 
int* hours_ptr; // hours pointer
 
double hourly_wage[3]; // array to store hourly wage input
 
char cont = ' '; // continue selector
char choice = ' '; // menu choice selector
char empl_name[4][16] = {"Berkley Boyd",
"Camden Caelan",
"Greer Gregor",
"Maisie Macaulay"}; // array to store employee names
char* empl_name_ptr; // employee name pointer
do
{
cout << "Welcome to Star Enterprise Salary Program " << endl;
cout << "===========================================" << endl;
cout << "A - Enter hourly rate for each employee " << endl;
cout << "B - Calculate work hours and weekly salary " << endl;
cout << "C - Display non-paid time for each employee" << endl << endl;
cout << "Please enter your choice: " << endl;
cin << choice;
cout >> endl;
if(choice == 'a' || choice == 'A')
{
for(input_loop = 0; input_loop < 4; ++input_loop)
cout << "Please enter the hourly rate for " << empl_name_ptr[0] + 1 << ": " << endl;
cin >> hourly_wage[hours];
}
else if(choice == 'b' || choice == 'B') // menu choice B calculate work hours &  salary 
{}
else if(choice == 'c' || choice == 'C') // display non-paid time accumulation
{}
else  // incorrect choice
{
cout << "Incorrect Selection! Please re-enter!" << endl;
}
}
while (cont == 'Y');  // loop choice to continue program
return 0;
}

Right now what I'm confused about is getting the input from the hourly wage loop. I probably named the loop wrong also. Anyhow, I know that I'm supposed to used the char array of names to supplement the name of the employee, and the get the "hourly_wage" input to store the wage of that employee to later calculate the salary. If I'm getting ahead of myself or if I should clarify myself, please feel free to. Basically, how close is my syntax so far. It should look like the sample output attached.

Thanks in advance for your help. I greatly appreciate it. Any help, criticism or suggestions are welcome.

TG

i figured out how to use string array, the problem I was having. It outputs what I want it to, e.g. ("Please enter the hourly rate for...") but I can't get it stop so I can input the rate, eg. $10.00.. Here is my modified code.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// variables
int input_loop = 0; // loop array for getting houry wage
 
int hours[4][5] = {{8,9,11,8,10}, // array to store hours
{12,7,12,11,12}, // "
{8,9,10,9,6}, // "
{8,7,8,6,6}}; // '
 
//int* hours_ptr; // hours pointer **commented out**
int name; // loop counter to get # of hours/employee (menu choice A)
double hourly_wage[3]; // array to store hourly wage input
double* hourly_wage_ptr = hourly_wage;
char cont = ' '; // continue selector
char choice = ' '; // menu choice selector
char empl_name[4][17] = {"Berkley Boyd","Camden Caelan","Greer Gregor","Maisie Macaulay"}; // array to store employee names
//char* empl_name_ptr; // employee name pointer **commented out**
 
 
do
{ 
cout << "Welcome to Star Enterprise Salary Program " << endl;
cout << "===========================================" << endl;
cout << "A - Enter hourly rate for each employee " << endl;
cout << "B - Calculate work hours and weekly salary " << endl;
cout << "C - Display non-paid time for each employee" << endl << endl;
 
cout << "Please enter your choice: " << endl;
cin >> choice;
cout << endl;
if(choice == 'a' || choice == 'A') // 
{
for(name = 0; name < 4; ++name)
cout << "Please enter the hourly rate for " << empl_name[name] << ": " << endl;
cin >> hourly_wage[name];
cout << endl;
}
/*
else if(choice == 'b' || choice == 'B')
{}
else if(choice == 'c' || choice == 'C')
{}*/
else
{
cout << "Incorrect Selection! Please re-enter!" << endl;
}
}
while (cont == 'Y'); // continue choice for program
return 0;

The output looks like this (cursor blinking at the end of the output text block & and no pause to input data, e.g. 10.00):
Please enter the hourly rate for Berkley Boyd:
Please enter the hourly rate for Camden Caelan:
Please enter the hourly rate for Greer Gregor:
Please enter the hourly rate for Maisie Macaulay:

Following is not clear:
1. Why is there a 2D array for hours? What does it indicate/store?
2. Why do "empl_name_ptr[0] + 1" in the code? What's the aim?
3. If you are expected to use C++, why not use STL containers? vector/map etc. Would be much easier.

Here are a few pointers.
1. Use "<< flush" instead of "<< endl" when you're taking a choice from user. It looks better !
2. To print names of all employees use this:

for( int i = 0; i < 4; i++ )
    cout << "Name of empoyee number " << i << " is " << empl_name[i] << endl ;

3. Variable cont is never assigned to. Loop is infinite. May be add one more choice in menu.
4. Avoid magic numbers. E.g.

char empl_name[4][16] = {"Berkley Boyd",
                             "Camden Caelan",
                             "Greer Gregor",
                             "Maisie Macaulay"};
for( int i = 0; i < 4; i++ )
    cout << "Name of empoyee number " << i << " is " << empl_name[i] << endl ;

Instead write it like this:

#define NUM_EMPL 4
char empl_name[NUM_EMPL][16] = {"Berkley Boyd",
                             "Camden Caelan",
                             "Greer Gregor",
                             "Maisie Macaulay"};
for( int i = 0; i < NUM_EMPL; i++ )
     cout << "Name of empoyee number " << i << " is " << empl_name[i] << endl ;

This way one you don't mis-type the value where you use it and second if you wish to change, you change in one place (and don't miss out other places).

thank you for your reply.

the array you asked about is to store the number of hours each employee worked; its to be used in a later part of my program where i'm to calculate the weekly salary of each employee using the hourly_wage (which i'm to obtain from this part I'm stuck at), multiplied by the number of hours worked (which is the array). other calculations are to be performed, but for now, I was just stuck printing that msg, now I can't get it to get the data...i'm rambling I apologize to future readers. my eyes are dying . i need some sleep. i'll definitely look over that when i wake up in a few hours. thanks again

Two things:
Please format your code. It's very difficult to follow.

And you input is not working the way you want it to. This series explains what is happening to you. cin and scanf() are really the same command. The first problem I noticed is your cin >> choice; command. The character description in the link above should tell you what's going on.

i'll take a look at that for future posts. thanks. let me dive back in. appreciate your help.

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.