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

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




asterisk bar chart

 
Reply to this topicStart new topic

asterisk bar chart

malar040984
16 Dec, 2007 - 11:17 PM
Post #1

New D.I.C Head
*

Joined: 12 Dec, 2007
Posts: 4


My Contributions
CODE
#include<fstream>
#include<iostream>
using namespace std;


int main ()
{
    ifstream in_stream;
    
    in_stream.open("people.dat");
    
    int people;
    
    in_stream>>people;
    
    cout <<"PRAIRIEVILLE POPULATION GROWTH"<<endl<<"(each * represents 1000 people)" << endl;
    
    
    for (int years = 1900; years <= 2000; years = years + 20)
    {
        cout<<years<<endl;  
        
        //print bar of asteriks
        for (int stars = 1; stars < people; stars = stars + 1000)
        {
            cout << '*';
            
        }
            
        
        cout << endl; //start a new line of output
    }
    
    
    
    
    
    in_stream.close();
    return 0;
    
    
}//end main


Now i need my program to get the input from another file n print the asterisk bar chart. Here my program prints 2000 asterisks for each year. pls help me
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Asterisk Bar Chart
17 Dec, 2007 - 05:23 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
What exactly do you need help with? the file operations? What will be the contents of the file?
User is offlineProfile CardPM
+Quote Post

malar040984
RE: Asterisk Bar Chart
17 Dec, 2007 - 05:32 AM
Post #3

New D.I.C Head
*

Joined: 12 Dec, 2007
Posts: 4


My Contributions
i have a separate input file, which has number of population. it means that this progrm doesnt require user input. i need the algorithm at the part where it will read the population n then prints the asterisks....

let say if 2000 population it will print **, if 3000 it prints *** and so on

User is offlineProfile CardPM
+Quote Post

pajamatime
RE: Asterisk Bar Chart
17 Dec, 2007 - 05:26 PM
Post #4

New D.I.C Head
*

Joined: 17 Dec, 2007
Posts: 2


My Contributions
To read the values in from the file I would use <fstream>. To decide on the amount of asterisks to show for each value will be based on the range of values that are present. Were you given the range of values that you could possibly see? Also will the values be numbers be easy to deal with like "2000" and "3000" or could you possibly see values like 2005 and 3002? More information would be nice, thanks.

PJT
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 11:32PM

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