Making graph in c++

Hi,

I want to make a program that gives you a graph with "*" and "." , "*" are % of how much work has been done and "." how much work has to be done. There can only be 80 signs ("*"/".").

So if i have for example 80% this means i have to get a graph that shows me 80% out of 80 signs "*" and other 20% "." .

Example:
1
2
3
4
5
6
7
8
9
...
  double a

  cout<<"How much work have you done: "<<endl;
  cin>>a;
// Now I need to have something like that : 
// You have done 80% of work.
// ****************************************************************....................................


Something like that...

Tnx
Last edited on
Lets break this down.

You are limited to 80 chars on the console

Someone does 80% of the 80 chars.

80 x .8 = 64

Now you just need to output a '*' to the console 64 times.

1
2
3
4
5
int numStars = //Code here

for(int i = 0; i < numStars; i++){
      //Code here
}


80% of 80 works out nicely but what if you have a fraction? Just pick a direction I would use floor http://www.cplusplus.com/reference/cmath/floor/?kw=floor

Last edited on
Hi there, this will give you the output you want
for example : Work done = 4% then the not done work is 96% so the result will be
( 4 stars / 96 dots )

How much work have you done :  4

You have done 4 % of work
****/...........................................................................
.....................


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;


int main ()
{
	int work;
	char Done = '*',NotDone = '.';

	cout << "How much work have you done :  ";
	cin >> work;
	cout << "\nYou have done " << work << " % of work\n";

	for ( unsigned int i = 0;i < work;i++ )
		cout << Done;
	cout << '/';
	work = 100 - work;
	for (unsigned int i = 0;i<work;i++ )
		cout << NotDone;
	cout << endl;

	return 0;
}


Good Luck, Zaki
Last edited on
Can I make graph so that u can choose how many lines you want?
For example:

1
2
3
4
5
6
7
8
9
...
    int N;
    cout<<"Enter number of lines:"<<endl;
    cin>>N;
   
    for(i = 0; i<N ; i++){
        //code
    }
...
Last edited on
Of course you can, and that's how you do it ( depending what you want on the //code )
Topic archived. No new replies allowed.