943,703 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1207
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 13th, 2008
0

Re: charting using for loops??

Click to Expand / Collapse  Quote originally posted by Sci@phy ...
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
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Oct 14th, 2008
0

Re: charting using for loops??

Ok, so this is the type of solution afg was looking for, with no arrays or dynamic allocation.

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Oct 14th, 2008
0

Re: charting using for loops??

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)
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
afg_91320 is offline Offline
55 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Jiberish Visual C++ Errors Un-Understandable
Next Thread in C++ Forum Timeline: Template problem - error status -1073741819





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC