| | |
charting using for loops??
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 0
im making a program where i will displaying the sales of each store using a sales bar chart.
user will input sales for each store.
after the input, a sales chart must be displayed using a for loop, with each '*' = $100 in sales
question: how can i make the * worth $100 so when ie: sales are $400 for the day, 4 * will be displayed? this is the trouble i am having with my for loop!
this is what i have so far.
thanks in advance!!
user will input sales for each store.
after the input, a sales chart must be displayed using a for loop, with each '*' = $100 in sales
question: how can i make the * worth $100 so when ie: sales are $400 for the day, 4 * will be displayed? this is the trouble i am having with my for loop!
this is what i have so far.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { double sale1, sale2, sale3, sale4, sale5; double total; int row; cout << "Enter today's sale for store 1: "; cin >> sale1; cout << "Enter today's sale for store 2: "; cin >> sale2; cout << "Enter today's sale for store 3: "; cin >> sale3; cout << "Enter today's sale for store 4: "; cin >> sale4; cout << "Enter today's sale for store 5: "; cin >> sale5; cout << endl; cout << "SALES BAR CHART" << endl; for (row = 0; row < 5; row++) { cout << '*'; cout << endl; } return 0; }
thanks in advance!!
So you want to print '*' n times, where n is a number of hundreds of dollars?
$300 - n = 3
$630 - n = 6
$690 - n = 6? (or n = 7?)
If so, divide each sale by n and store it in int (in that way $630 will end up being 6.3, but stored in int: 6!)
Then add another loop inside row-loop that will print cout<<'*' for n times.
Like this pseudocode:
$300 - n = 3
$630 - n = 6
$690 - n = 6? (or n = 7?)
If so, divide each sale by n and store it in int (in that way $630 will end up being 6.3, but stored in int: 6!)
Then add another loop inside row-loop that will print cout<<'*' for n times.
Like this pseudocode:
C++ Syntax (Toggle Plain Text)
for rows loop for n loop print * end n loop print newline end rows loop
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 0
i followed your advice, but i feel like this code has some errors:
C++ Syntax (Toggle Plain Text)
cout << "SALES BAR CHART" << endl; for (row = 0; row < 5; row++); { cout << '*'; cout << endl; } for (n = 100) { sale1 /= n; sale2 /= n; sale3 /= n; sale4 /= n; sale5 /= n; }
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 0
•
•
•
•
i followed your advice, but i feel like this code has some errors:
cout << "SALES BAR CHART" << endl;for (n = 100) { sale1 /= n; sale2 /= n; sale3 /= n; sale4 /= n; sale5 /= n; }for (row = 0; row < 5; row++); { cout << '*'; cout << endl; }
Last edited by afg_91320; Oct 12th, 2008 at 9:56 pm.
•
•
Join Date: Oct 2008
Posts: 32
Reputation:
Solved Threads: 4
Using dynamic memory allocation, you can come up with this:
It's 3:18am and I'm tired. PM me if you have any questions. I don't have problems adding you to msn either.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <alloc.h> using namespace std; int main() { int nstores, *sales; cout << "SALES BAR CHART" << endl; cout << "---------------" << endl; cout << "Enter the number of stores: "; cin >> nstores; sales = (int *) malloc(sizeof(int)*nstores); for(int i=0; i<nstores; i++) { cout << "Enter today's sales for store number " << i+1 << ": "; cin >> sales[i]; sales[i] /= 100; } cout << "\n\n"; for( int i=0; i<nstores; i++) { cout << "Store " << i+1 << ": "; for (int j=0; j<sales[i]; j++) cout << '*'; cout << "\n"; } system("pause>nul"); return 0; }
It's 3:18am and I'm tired. PM me if you have any questions. I don't have problems adding you to msn either.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Jiberish Visual C++ Errors Un-Understandable
- Next Thread: Template problem - error status -1073741819
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





