very, very new and don't know squat - need help

I'm not sure where I have fell off, but I am just not getting something (obviously something important). I have read several answers/questions, but have not figured out my problem to the problem.

Write a program that accepts input like the program in Display 7.8 and that outputs a bar graph like the one in that display EXCEPT that your program will output the bars vertically rather than horizontally. A two-dimensional array may be useful.

This is the 7.8 display, but it will not run on CodeBlocks although I typed it exactly from the book.

//Reads data and displays a bar graph showing productivity for each plant.
#include <iostream>
#include <cmath>
const int NUMBER_OF_PLANTS = 4;

void input_data(int a[], int last_plant_number);

void scale(int a[], int size);

void graph(const int asterisk_count[], int last_plant_number);

void get_total (int& sum);

int round(double number);

void print_asterisks (int n);

int main ()
{
using namespace std;
int production [NUMBER_OF_PLANTS];

cout<<"This program displays a graph showing\n"
<<"production for each plant in the company.\n";
input_data(production, NUMBER_OF_PLANTS);
scale(production, NUMBER_OF_PLANTS);
graph(production, NUMBER_OF_PLANTS);
return 0;
}
//Uses iostream:
void input_data(int a[], int last_plant_number)
{
using namespace std;
for (int plant_number = 1;
plant_number <= last_plant_number; plant_number ++)
{
cout<<endl;
<<"Enter production data for plant number "<<plant_number<<endl;
get_total(a[plant_number – 1]);
}
}

void get_total(int& sum)
{
using namespace std;
cout<<"Enter number of units produced by each department.\n"
<<"Append a negative number to the end of the list.\n";

sum = 0;
int next;
cin>>next;
while (next >= 0)
{
sum = sum + next;
cin>>next;
}
cout<<"Total = "<<sum<<endl;
}
void scale (int a[], int size)
{for (int index = 0; index < size; index++)
a[index] = round(a[index]/1000.0);
}
int round(double number)
{
using namespace std;
return static_cast<int>(floor (number + 0.5);
}
void graph (const int asterisk_count [], int last_plant_number)
{
using namespace std;
cout<< "units produced in thousands of units:\n";
for (int plant_number 1;
plant_number <= last_plant_number; plant_number++)
{
cout<<"Plant #"<<plant_number<<" ";
print_asterisks(asterisk_count[plant_number – 1]);
return 0;
}
}



Thank you for any help
Last edited on
Whatever is meant to print out as text needs to be enclosed by double quotes " ".

for example - if this is all text, then this....
1
2
cout<<This program displays a graph showing\n
<<production for each plant in the company.\n;


...should be like this

cout<<"This program displays a graph showing production for each plant in the company.\n";


If you can edit your post - highlight the code, then click on the <> button in the Format palette at the right side of the post, it'll format your code for the forum and make it a lot easier to read :)
I had the "" in the program - just not what I typed in Word because they kept messing me up! I clicked on the <>, but it didn't change anything.
Word does its own formatting so it's not the best text editor for writing code unfortunately. Here's your code using the forum code tag formatter.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <cmath>
const int NUMBER_OF_PLANTS = 4;

void input_data(int a[], int last_plant_number);
void scale(int a[], int size);
void graph(const int asterisk_count[], int last_plant_number);
void get_total (int& sum);
int round(double number);
void print_asterisks (int n);

int main ()
{
	using namespace std;
	int production [NUMBER_OF_PLANTS];

	cout<<"This program displays a graph showing\n" <<"production for each plant in the company.\n";
	input_data(production, NUMBER_OF_PLANTS);
	scale(production, NUMBER_OF_PLANTS);
	graph(production, NUMBER_OF_PLANTS);
	return 0;
}
//Uses iostream:
void input_data(int a[], int last_plant_number)
{
	using namespace std;
	for (int plant_number = 1;plant_number <= last_plant_number; plant_number ++)
	{
		cout<<endl;
		<<"Enter production data for plant number "<<plant_number<<endl;
		get_total(a[plant_number – 1]);
	}
}

void get_total(int& sum)
{
	using namespace std;
	cout<<"Enter number of units produced by each department.\n" <<"Append a negative number to the end of the list.\n";
	sum = 0;
	int next;
	cin>>next;
	while (next >= 0)
	{
		sum = sum + next;
		cin>>next;
	}
	cout<<"Total = "<<sum<<endl;
}
void scale (int a[], int size)
{
	for (int index = 0; index < size; index++)
		a[index] = round(a[index]/1000.0);
}
int round(double number)
{
	using namespace std;
	return static_cast<int>(floor (number + 0.5);
}
void graph (const int asterisk_count [], int last_plant_number)
{
	using namespace std;
	cout<< "units produced in thousands of units:\n";
	for (int plant_number 1;plant_number <= last_plant_number; plant_number++)
	{
		cout<<"Plant #"<<plant_number<<" ";
		print_asterisks(asterisk_count[plant_number – 1]);
		return 0;
	}
}
How did you do that? I before reposting, I copied from Codeblocks, thinking it would keep the format and coloring.
I am just going to drop out of school. If I can't figure this easy stuff out, there is no sense in even trying any longer.

Thanks for your help
Did you highlight the code before clicking the <> button? If you didn't, the button wouldn't do anything. Alternatively, you can just type the tags manually [ code ] before the code starts and [ / code ] after it ends. (remove the spaces inside the brackets)

You're missing the definition for the print_asterisks function, I don't know if just didn't get copied and pasted over.

You don't need a return 0 on line 67 since graph is a void function.
Line 63 is missing an =

round is actually the name of a function built in to C++, so I'd rename your round function to something else.

line 30 needs a cout <<
FIXED THOSE, BUT NEW ERRORS CROPPED UP

IN FUNCTION VOID_INPUT DATA (INT*, INT)
LINE 31 EXPECTED ] BEFORE NUMERIC CONSTANT
EXPECTED ) BEFORE NUMERIC CONSTANT
EXPECTED ; BEFORE ] TOKEN

int rnd(double number)
LINE 57 EXPECTED ) BEFORE ; TOKEN

void graph (const int*, INT)
LINE 66 EXPECTED ) BEFORE NUMERIC CONSTANT
EXPECTED ; BEFORE ] TOKEN

WHAT IS A "TOKEN"??

#include <iostream>
#include <cmath>
const int NUMBER_OF_PLANTS = 4;

void input_data(int a[], int last_plant_number);
void scale(int a[], int size);
void graph(const int asterisk_count[], int last_plant_number);
void get_total (int& sum);
int rnd(double number);
void print_asterisks (int n);

int main ()
{
using namespace std;
int production [NUMBER_OF_PLANTS];

cout<<"This program displays a graph showing\n" <<"production for each plant in the company.\n";
input_data(production, NUMBER_OF_PLANTS);
scale(production, NUMBER_OF_PLANTS);
graph(production, NUMBER_OF_PLANTS);
return 0;
}
//Uses iostream:
void input_data(int a[], int last_plant_number)
{
using namespace std;
for (int plant_number = 1;plant_number <= last_plant_number; plant_number ++)
{
cout<<endl;
cout<<"Enter production data for plant number "<<plant_number<<endl;
get_total(a[plant_number – 1]);
}
}

void get_total(int& sum)
{
using namespace std;
cout<<"Enter number of units produced by each department.\n" <<"Append a negative number to the end of the list.\n";
sum = 0;
int next;
cin>>next;
while (next >= 0)
{
sum = sum + next;
cin>>next;
}
cout<<"Total = "<<sum<<endl;
}
void scale (int a[], int size)
{
for (int index = 0; index < size; index++)
a[index] = rnd(a[index]/1000.0);
}
int rnd(double number)
{
using namespace std;
return static_cast<int>(floor (number + 0.5);
}
void graph (const int asterisk_count[], int last_plant_number)
{
using namespace std;
cout<< "units produced in thousands of units:\n";
for (int plant_number=1;plant_number <= last_plant_number; plant_number++)
{
cout<<"Plant #"<<plant_number<<" ";
print_asterisks(asterisk_count[plant_number – 1]);
}
}
If the minus sign in the lines that have this - [plant_number-1] got copied in from Word, it may not be the right character. I had to delete the characters in between the r in number and the 1 and replace the minus sign.

line 57 is missing a closing )
return static_cast<int>(floor (number + 0.5);

You're calling the print_asterisks function on line 66 but it isn't defined anywhere that I can se..
Topic archived. No new replies allowed.