3 Replies - 480 Views - Last Post: 24 March 2019 - 12:50 AM Rate Topic: **--- 3 Votes

#1 Beginner(30)   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-March 19

I need some help.

Posted 21 March 2019 - 05:03 PM

I new to programming and I really need some help on this c++ assignment. I have to write a program that codes the data below into arrays and draws a bar graph(using (*) for the bars)for the top data items as requested by the user.
CO2 Emissions by Country in Millions of Metric Tons
China 9041 ****************************************************************
USA 4998 ***********************************
India 2066 **************
Russia 1469 **********
Japan 1142 ********
Germany 730 *****
S.Korea 586 ****
Iran 553 ***
Canada 549 ***
* = 141 million metric tons
Shortest bar is 3 *'s


Heres what I got.

#include<iostream>
using namespace std;
/**
    On a single line, displays the following information: label, data,
    bar graph of data.

    @param label The name of the data item
    @param data The amount of the data item
    @param step The amount of data per asterisk
    @return number of stars
*/
int drawBar(string label[], double data[], double step[])
{
    int numStars = data / step;
    // display label and data
    // for loop to draw bar
    return numStars;
}
int main(){
	int n = 0;
	string label[] ={China, USA, India, Russia, Japan, Germany, S.Korea, Iran Canada};
	double data[] = {9041, 4998, 2066, 1496, 1142, 730, 586, 553, 549};
	double step[] = {64, 35, 14, 10, 8, 5, 4, 3, 3};
	cout << "Enter number of items to display: \n";
	cin >> n;
	int S = 0;
	int S = drawBar(string label[], label[], step[]);


This post has been edited by #define: 21 March 2019 - 06:12 PM
Reason for edit:: correct code box


Is This A Good Question/Topic? 0
  • +

Replies To: I need some help.

#2 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1858
  • View blog
  • Posts: 6,690
  • Joined: 19-February 09

Re: I need some help.

Posted 21 March 2019 - 06:20 PM

Hi, welcome to Dream in Code.

Is the drawBar function to print one bar? If so, you don't need to pass the arrays, but a string and two doubles.

You are calculating the number of stars, but step appears to be the number of stars already.
Was This Post Helpful? 0
  • +
  • -

#3 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1858
  • View blog
  • Posts: 6,690
  • Joined: 19-February 09

Re: I need some help.

Posted 21 March 2019 - 06:26 PM

Is there any specific question you wished to ask?
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 976
  • View blog
  • Posts: 3,849
  • Joined: 13-June 14

Re: I need some help.

Posted 24 March 2019 - 12:50 AM

Your code shouldn't even be compiling, as there are obvious errors. Aren't you seeing the errors from the compiler?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1