Converting to Multidimensional Arrays

Hi all, i have the following codes, but i would like to know how can i transform my codes to become using multidimensional array codes. Appreciate if anyone could show me and help me to convert it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
	char name [100];
	
	cout<<"This is an Calculator to calculate number of Employees having total salary and bonus more than 1000" << endl;
	cout<<"What is your name?" << endl;
	cin.getline (name,100);
	cout<<"Hello, " << name << "." << endl;

	int Salary[10], Bonus[10], lCount=0, gCount=0, i=0, j=0;
	cout<<"Please Enter Employees Salary (Max 10 Employees)" << endl;

	for (i=0; i<10; i++)
{
	cout<<"Enter Employee " << i+1 << " Salary : " ;
	cin>>Salary[i];
	cin.ignore();
}

	for (j=0; j<10; j++)
{
    cout<<"Enter Employee " << j+1 << " Bonus : ";
    cin>>Bonus[j];
    cin.ignore();
}

	for (i=0; i < 10; ++i)
{
	if (Salary[i]+Bonus[i]>1001)
	{lCount++;}
	else 
	{gCount++;}
}

	cout<<"There are " << lCount << " Employees with Salary and Bonus more then 1000\n";
	cout<<"There are " << gCount << " Employees with Salary and Bonus less then 1000\n";

	cin.get();
}
please explain how you want those multidimensional arrays to look like.
Wait a minute...

convert TO multidimentional arrays? Why that's just lunacy.
hi, the output will be the same (calculating the the numbers of employees with salary and bonus more and less than 1000) using multidimensional arrays.

Magnificence7 - anything is fine, maybe u could show me your way ?

thanks.
I'm not sure about line 11, I think it's supposed to be: getline( inputstream, storage );
Also mulitiD arrays are a bad idea, because things typically get more complicated.
http://cplusplus.com/forum/articles/17108/
Last edited on
I don't even see how an MD array would apply here.
but is there a way to use MD array to calculate the numbers of employees with salary and bonus more and less than 1000 ?

thanks.
I guess so. But why would you want to do that? It would just make your code unclear and confusing.
i wanted to see the differences between this 2 sets of codes.

would u be able to show me ? a big thank you to u if u can show me. :)
Well what you're asking kind of makes no sense. MD arrays are completely the wrong tool for this job.

Say you have a 2D array for the salary. What would the 2nd dimension represent? It makes no sense.

It's like trying to drive a screw with a hammer. Sure you can make it work if you try hard enough, but it's ridiculous.
perhaps he means:
1
2
name  |  salary  |  bonus
name  |  salary  |  bonus


Even then a 1D array of objects would be better.
edit: or std::strings, rather than cstrings.
Last edited on
Topic archived. No new replies allowed.