User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,654 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,402 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

Programming Problem

Join Date: May 2007
Posts: 266
Reputation: quintoncoert is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
quintoncoert quintoncoert is offline Offline
Posting Whiz in Training

Re: Programming Problem

  #5  
Jul 10th, 2007
here is a skeleton program which aught to get you started. i suggested something similar to another student asking for help. it is called a sentinel controlled loop. it continuously asks for scout name as well as the number of cans for that scout and will continue to ask until you type "end" where they ask for name. note how the loop says ....while ( scout != "end" )

this code was compiled on Bloodshed's Dev-C++ 4.9.9.2 IDE which uses the ming32 compiler but i say this only if it gives problems on VC++. others better at c++ than myself would then be able to help you. but narue told me that the world has moved on to compilers which works with the standard language so you should have little trouble adapting it to visual c++. I compiled it and it ran. like i said it should get you started.

also i as well as the others said. you are a bit unclear. for example are the scout name and can total to be stored in an array? then declare the array before the loop and add the total to the specific scout's location in the array.
or is it stored in a file( sorry.there i cant help you! i dont know how to open files in c++) then the process is similar but instead of adding to an array you write it to disk. also does a scout brings all his cans at one go or can he come back later with some more( this might require a double loop.). aks if you need more help. sorry for the bad spacing but i have no idea on how to indent the code in a thread.
  1. #include <iostream>
  2. using std::cin; //you probably dont need this because of using namespace std;
  3. using std::cout; //or this
  4. using std::endl; //or this
  5. using namespace std;
  6.  
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. string scout;
  11. int cans;
  12.  
  13. //receive first scout name or end to exit program
  14. cout << "Enter the name of the scout. Otherwise type end to exit the program." << endl;
  15. cin >> scout;
  16.  
  17. while ( scout != "end" )
  18. {
  19. cout << "enter the the number of cans" << endl;
  20. cin >> cans;
  21.  
  22. /* here comes the code which add the cans to some total or write it to a file or something for a given scout whom had his name entered. */
  23.  
  24. //enter next value which could be the sentinel
  25. cout << "Enter the name of the scout. Otherwise type end to exit the program." << endl;
  26. cin >> scout;
  27.  
  28. }
  29.  
  30. //after all the cans are entered
  31. //average cans = total number of cans divided by number of scouts
  32.  
  33. //and all other code including display the output.
  34.  
  35. system("PAUSE");
  36. return EXIT_SUCCESS;
  37. }
Last edited by WaltP : Jul 10th, 2007 at 1:55 pm. Reason: After 113 posts and explanation of CODE tags twice in this thread alone, you'd by now know how to use them. Maybe they're beyond Java programmer's abilities?
Reply With Quote  
All times are GMT -4. The time now is 11:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC