I really hate to ask this but could someone look this over and see if I did something wrong as far as why the functions do not return right?
Code:#include <cstdlib> #include <iostream> #include <iomanip> #include <cstring> #include <ctime> using namespace std; void random(); void multiples(); void numbers(); //------------------------------------------ int main() { //------------------------------------------ cout<< "Pick a program to do. Enter 0 to quit.\n"; cout<< "Choice 1 - random selection\nChoice 2 - multiples\nChoice 3 - Number counting\n"; int choice=cin.get(); do{ switch (choice) { case '1': random(); break; case '2': multiples(); break; case '3': numbers(); break; default: cout<< "Try again "; } }while (choice != 0); return 0; } //------------------------------------------ void random() { //------------------------------------------ int score[101]; int frequency[101]; int upick=1; while (upick!=0) { //copy 0 into the first 101 bytes of score and frequency memset(score, 0, 101*sizeof(int)); memset(frequency, 0, 101*sizeof(int)); cout<< "Pick a number between 1 and 100 and I will randomly select them and "<< endl << "then I will output the results.\n\nPick a number between 1 and 100: "; cin>> upick; cout<< endl; srand(time(0)); // Score entering loop int entered=0, l=0; for (int i=0; i<101; i++) { score[i]=1+rand()%upick; entered++; if (score[i]>0){ cout << score[i]<< "\t"; ++l; } if (l==9) { l=0; cout<< "\n"; } } cout<< "\n\n"; system("PAUSE"); // Score counting loop for (int i=0; i < entered; i++) ++frequency[score[i]]; cout << "SCORE" << setw(13) << "FREQUENCY" << setw(8)<< "GRAPH"<< endl; // Score output loop for (int i=0; i < 101; i++) { if (frequency[i]>0) { cout<< setw(7) << i << setw(8) << frequency[i]<< setw(6)<< " "; // Print graph for(int j=0; j < frequency[i]; j++) { cout << '*'; } cout << endl; } } cout<<"QUIT? Enter 0=yes 1=no: "; cin>> upick; } return; } //------------------------------------------ void multiples() { //------------------------------------------ cout<<"Enter in a number between 1 and 12100 and I will calculate the multiples of\nthat number up to 86. Press -1 to quit.\n"; for (int y; y<12100;) { cout<<"\n0 to quit. Your number: "; cin>> y; while (y>12100) {cout<<"too big\n"; cin>>y;} if (y<1) break; int z=0; cout<< "\n"; for (int x=1; x<86; ++x) { if (z>=4) {cout<< "\n"; z=0;} cout << x<< "*"<< y<< "= " << x*y << setw(5); ++z; } y=0; cout<< endl; } return; } //------------------------------------------ void numbers() { //------------------------------------------ int score[1000001]; int frequency[1000001]; int temp=1; while (temp!=0) { //copy 0 into the first 1000001 bytes of score and frequency memset(score, 0, 1000001*sizeof(int)); memset(frequency, 0, 1000001*sizeof(int)); cout << "This program will allow you to enter in 1 million numbers up to a value "<< endl << "of 1 million and it will chart how many times you entered in that number."<< endl << "\nEnter scores (Limit: 1000000):\n"; // Score entering loop int entered=0; for (int i=0; i < 1000001; i++) { cout << "Enter 0 when finished. Next score: "; cin >> temp; while(temp > 1000000) { cout << "Score out of range. Enter again: "; cin >> temp; } if (temp<1) break; score[i] = temp; entered++; } // Score counting loop for (int i=0; i < entered; i++) ++frequency [score[i]]; cout << "\nSCORE" << setw(13) << "FREQUENCY" << setw(8)<< "GRAPH"<< endl; // Score output loop for (int i=0; i < 1000001; i++) { if (frequency[i]>0) { cout<< setw(7) << i << setw(8) << frequency[i]<< setw(6)<< " "; // Print graph for(int j=0; j < frequency[i]; j++) { cout << '*'; } cout << endl; } } cout<< "QUIT? 0=yes 1=no "; cin>> temp; } return; }




Reply With Quote