charting using for loops??

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: charting using for loops??

 
0
  #11
Oct 13th, 2008
Originally Posted by Sci@phy View Post
If we want to go dynamic, why not use new instead of malloc()?
Didn't I do that?
I'm just a student as well, if you know of a different way to do that dynamically please post it and explain the differences.
afg, do you need help understanding dynamic memory allocation? I'm not a master on the subject but I know the basics I can make a chart to explain it to you just like my teacher did =3
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: charting using for loops??

 
0
  #12
Oct 14th, 2008
Ok, so this is the type of solution afg was looking for, with no arrays or dynamic allocation.

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int sale1, sale2, sale3, sale4, sale5;
  8.  
  9. cout << "Enter today's sale for store 1: ";
  10. cin >> sale1;
  11. sale1 /= 100;
  12.  
  13. cout << "Enter today's sale for store 2: ";
  14. cin >> sale2;
  15. sale2 /= 100;
  16.  
  17. cout << "Enter today's sale for store 3: ";
  18. cin >> sale3;
  19. sale3 /= 100;
  20.  
  21. cout << "Enter today's sale for store 4: ";
  22. cin >> sale4;
  23. sale4 /= 100;
  24.  
  25. cout << "Enter today's sale for store 5: ";
  26. cin >> sale5;
  27. sale5 /= 100;
  28.  
  29. cout << endl;
  30. cout << "SALES BAR CHART" << endl;
  31. cout << "---------------" << endl;
  32.  
  33. cout << "Store 1: ";
  34. int row;
  35. for ( row = 0; row < sale1; row++)
  36. cout << '*';
  37.  
  38. cout << "\nStore 2: ";
  39. for ( row = 0; row < sale2; row++)
  40. cout << '*';
  41.  
  42. cout << "\nStore 3: ";
  43. for (int row = 0; row < sale3; row++)
  44. cout << '*';
  45.  
  46. cout << "\nStore 4: ";
  47. for (int row = 0; row < sale4; row++)
  48. cout << '*';
  49.  
  50. cout << "\nStore 5: ";
  51. for (int row = 0; row < sale5; row++)
  52. cout << '*';
  53.  
  54. //cin.get();
  55. //cin.ignore();
  56. system("pause>nul");
  57. return 0;
  58. }
You can either use
system("pause>nul");
alone to pause the program, or use both
cin.get();
cin.ignore();
together to achieve the same result.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: afg_91320 is an unknown quantity at this point 
Solved Threads: 0
afg_91320 afg_91320 is offline Offline
Junior Poster in Training

Re: charting using for loops??

 
0
  #13
Oct 14th, 2008
thanks!
one more question! (sorry!!!)

if the user inputs like 990 in sales, and you want to round up to 1000 and show 10 * instead of 9, would you use the double instead of int? and what would the same thing apply if the user were to enter a decimal value? (must be able to show dollars and cents)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC