Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,450 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,074 people online right now. Registration is fast and FREE... Join Now!




help with array

 
Reply to this topicStart new topic

help with array

sumlani
8 Aug, 2008 - 02:45 PM
Post #1

New D.I.C Head
*

Joined: 26 Jan, 2008
Posts: 26



Thanked: 3 times
My Contributions
Attached File  proj2.doc ( 26k ) Number of downloads: 2

I can't get the second portion of my program to work, can you please help?

cpp
#include <iostream>

using namespace std;

int main()
{
int count[9] = {0};

while (1)
{
cout << "Enter employee gross sales (-1 to end): ";
double gross;
cin >> gross;

if (gross == -1.0)
break;

double sale = gross * 0.09 + 200;
cout << "Employee Commission is $" << sale << endl;

int index = (int(sale) - 200) / 100;

if (index > 8)
index = 8;

++count[index];
}

cout << endl << "Employees in the range:\n";

for (int i = 200; i <= 1000; i += 100)
{
if (i < 1000)
cout << "$" << i << "-$" << i + 99 << " : ";
else
cout << "Over $1000 : ";

cout << count[(i - 200) / 100] << endl;
}

return 0;
}



I've sent an attachment of the teachers requirements, thanks in advance for any & all help.

Mod edit: Please code.gif
Thanks, gabehabe smile.gif
User is offlineProfile CardPM
+Quote Post

DTR
RE: Help With Array
8 Aug, 2008 - 03:42 PM
Post #2

New D.I.C Head
*

Joined: 7 Aug, 2008
Posts: 33


My Contributions
The problem in your code seems to be the fact that the console window is closed automatically when the program reaches its last command, which is normal.

Easiest way for now would be to add command:

system("pause");

right before the end of your program: return 0;


Edit:
Gee. I really hope that this was really the problem you had trouble with. I was a bit hasty in reply.

This post has been edited by DTR: 8 Aug, 2008 - 03:49 PM
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Help With Array
8 Aug, 2008 - 04:14 PM
Post #3

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,539



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
It isn't. It's how you calculate the index, judging from a quick look.

Then again, I'm knackered sad.gif

Anyway, try this:
cpp
#include <iostream>

using namespace std;

int main()
{
int count[9] = {0};
double gross;
bool quit = false;

while (!quit)
{
cout << "Enter employee gross sales (-1 to end): ";
gross = 0.0;
cin >> gross;

if (gross == -1.0)
quit = true;

double sale = gross * 0.09 + 200;
cout << "Employee Commission is $" << sale << endl;

int index = 0;
for (int i = 300; i <= 1000; i += 100)
{
if (sale < i)
break;
index++;
}

if (index > 8)
index = 8;

if (sale >= 200.0)
{
count[index]++;
cout << "hi";
}
}

cout << endl << "Employees in the range:\n";

for (int i = 200; i <= 1000; i += 100)
{
if (i < 1000)
cout << "$" << i << "-$" << i + 99 << " : ";
else
cout << "Over $1000 : ";

cout << count[(i - 200) / 100] << endl;
}

return 0;
}

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 03:02PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month