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.
#include <iostream>
using std::cin; //you probably dont need this because of using namespace std;
using std::cout; //or this
using std::endl; //or this
using namespace std;
int main(int argc, char *argv[])
{
string scout;
int cans;
//receive first scout name or end to exit program
cout << "Enter the name of the scout. Otherwise type end to exit the program." << endl;
cin >> scout;
while ( scout != "end" )
{
cout << "enter the the number of cans" << endl;
cin >> cans;
/* 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. */
//enter next value which could be the sentinel
cout << "Enter the name of the scout. Otherwise type end to exit the program." << endl;
cin >> scout;
}
//after all the cans are entered
//average cans = total number of cans divided by number of scouts
//and all other code including display the output.
system("PAUSE");
return EXIT_SUCCESS;
}
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?