I'm supposed to create a program with a switch and using voids to execute number of codes, that includes finding sum, average, maximum, and minimum, please read my code:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- void WELCOME();
- void triangleFormula();
- void goodbyeMessage();
- void arithmeticFormula();
- void secondArithmeticFormula();
- void thePowerOf();
- void goodbyeMessage();
- // these are the voids that is used
- // in the switches
- int adminInput;
- int userInput;
- int selection (0);
- int sum (0);
- int average(0);
- int inputTimes (0);
- int base;
- int exponent;
- double answerForPower;
- int numberOfSet;
- int dataForSystem;
- const int SENTINEL_VALUE (-777);
- // this is used to let the user stop
- // manually in the arithmetic sets
- // so that the numbers could be calculated
- int main ()
- { //main
- WELCOME();
- // welcomming message
- system("pause");
- system("cls");
- while (true)
- { //while
- cout << "Please choose from" << endl;
- cout << "1. Draw an inverted triangle of your chosen height using your chosen letter" << endl;
- cout << "2. Enter some numbers and learn the sum, average, min, and max of your inputs" << endl;
- cout << "3. Same 2, but with a different way to end inputting" << endl;
- cout << "4. Let me Calculate a^b (a raised to the b) for whatever a and b you'd like" << endl;
- cout << "5. Quit this program" << endl;
- // this is the menu for the users to read
- // so that the user could input numbers
- // from 1 to 5
- cout << endl;
- cout << "Enter choice " << endl;
- cin >> adminInput;
- system ("cls");
- switch (adminInput)
- { // switch
- case 1:
- triangleFormula ();
- selection++;
- break;
- case 2:
- arithmeticFormula ();
- selection++;
- break;
- case 3:
- secondArithmeticFormula ();
- selection++;
- break;
- case 4:
- thePowerOf ();
- selection++;
- break;
- case 5:
- goodbyeMessage ();
- return 0;
- } // switch
- } // while
- } // main
- void WELCOME ()
- { // welcome
- cout << "Welcome to my program" << endl;
- cout << "I can do several things for you." << endl;
- cout << "When you are ready to enter my program" << endl;
- cout << "Hit any key" << endl;
- } // welcome
- void triangleFormula ()
- { // triangle formula
- int tallness;
- char userLetter;
- cout << "Which letter to use for the triangle" << endl;
- cin >> userLetter;
- cout << "How tall?" << endl;
- cin >> tallness;
- for (int i(0); i<=tallness; i++)
- { // first for
- for (int j(1); j<=(tallness-i); j++)
- { // second for
- cout << userLetter;
- } // second for
- cout << endl;
- } // first for
- system("pause");
- system("cls");
- } // triangle formula
- void goodbyeMessage ()
- { // goodbye message
- cout << "You made " << selection << " selections" << endl;
- cout << "Thank you for using my program" << endl;
- system("pause");
- system("cls");
- } // goodbye message
- void arithmeticFormula ()
- { // arithmetic Formula
- cout << "Please enter a set of integers " << endl;
- cout << "Please type -777 to stop" << endl;
- while (userInput != SENTINEL_VALUE)
- { // while
- cin >> userInput;
- if (userInput !=SENTINEL_VALUE)
- { // if
- inputTimes++;
- sum+=userInput;
- } // if
- } // while
- int max (0);
- int min (0);
- if ((max < userInput)&&(min!=SENTINEL_VALUE))
- { // if
- max = userInput;
- } // if
- if ((min > userInput)&&(min!=SENTINEL_VALUE))
- { //if
- min = userInput;
- } //if
- average = sum / inputTimes;
- cout << "The sum of your input is" << endl;
- cout << sum << endl;
- cout << "The average of your input is" << endl;
- cout << average << endl;
- cout << "The Maximum input is" << endl;
- cout << max << endl;
- cout << "The Minimum input is" << endl;
- cout << min << endl;
- } // arithmetic Formula
- void secondArithmeticFormula ()
- { // second arithmetic Formula
- int setsOfData(0);
- int secondInputTimes (0);
- int accum (0);
- int secondUserInput(0);
- int dataForSystem;
- cout << "How many sets of data will be entered?" << endl;
- cin >> setsOfData;
- while (setsOfData !=SENTINEL_VALUE)
- { //while
- for (int i=setsOfData;setsOfData<=i;i++)
- { //for
- cout << "Please begin entering data set." << endl;
- cout << "Enter -777 to indicate you are done with this set." << endl;
- cin >> dataForSystem;
- cin >> secondUserInput;
- secondInputTimes++;
- accum+=secondUserInput;
- average = sum / secondInputTimes;
- } //for
- } // while
- cout << "The sum of your input is" << endl;
- cout << sum << endl;
- cout << "The average of your input is" << endl;
- cout << average << endl;
- cout << "The Maximum input is" << endl;
- int max(0);
- int min(0);
- if (max < secondUserInput)
- { // if
- max = secondUserInput;
- } // if
- else if (min > secondUserInput)
- {
- min = secondUserInput;
- }
- cout << "The Minimum input is" << endl;
- cout << min << endl;
- } // second arithmetic formula
- void thePowerOf ()
- { // the power of
- cout << "Please enter the first number for the base" << endl;
- cin >> base;
- cout << "Please enter the second number for the exponent" << endl;
- cin >> exponent;
- cout << "Your Base and Exponent is" << endl;
- cout << base << " "<< "and " << exponent << " which is" << base << "^ (raised to the)" << exponent << endl;
- cout << "The number is" << endl;
- for (int i=1; i<exponent;i++)
- {
- base*=base;
- }
- cout << base << endl;
- } // the power of
especially the:
Expand|Select|Wrap|Line Numbers
- void arithmeticFormula ()
- { // arithmetic Formula
- cout << "Please enter a set of integers " << endl;
- cout << "Please type -777 to stop" << endl;
- while (userInput != SENTINEL_VALUE)
- { // while
- cin >> userInput;
- if (userInput !=SENTINEL_VALUE)
- { // if
- inputTimes++;
- sum+=userInput;
- } // if
- } // while
- int max (0);
- int min (0);
- if ((max < userInput)&&(min!=SENTINEL_VALUE))
- { // if
- max = userInput;
- } // if
- if ((min > userInput)&&(min!=SENTINEL_VALUE))
- { //if
- min = userInput;
- } //if
- average = sum / inputTimes;
- cout << "The sum of your input is" << endl;
- cout << sum << endl;
- cout << "The average of your input is" << endl;
- cout << average << endl;
- cout << "The Maximum input is" << endl;
- cout << max << endl;
- cout << "The Minimum input is" << endl;
- cout << min << endl;
- } // arithmetic Formula
and my minimum would always be the SENTINEL_VALUE (-777), because I had to input -777 to stop it from reading
the sum and average works perfectly.
--------------------------------------------------------------------------------------
then there is another problem here:
Expand|Select|Wrap|Line Numbers
- void secondArithmeticFormula ()
- { // second arithmetic Formula
- int setsOfData(0);
- int secondInputTimes (0);
- int accum (0);
- int secondUserInput(0);
- int dataForSystem;
- cout << "How many sets of data will be entered?" << endl;
- cin >> setsOfData;
- while (setsOfData !=SENTINEL_VALUE)
- { //while
- for (int i=setsOfData;setsOfData<=i;i++)
- { //for
- cout << "Please begin entering data set." << endl;
- cout << "Enter -777 to indicate you are done with this set." << endl;
- cin >> dataForSystem;
- cin >> secondUserInput;
- secondInputTimes++;
- accum+=secondUserInput;
- average = sum / secondInputTimes;
- } //for
- } // while
- cout << "The sum of your input is" << endl;
- cout << sum << endl;
- cout << "The average of your input is" << endl;
- cout << average << endl;
- cout << "The Maximum input is" << endl;
- int max(0);
- int min(0);
- if (max < secondUserInput)
- { // if
- max = secondUserInput;
- } // if
- else if (min > secondUserInput)
- {
- min = secondUserInput;
- }
- cout << "The Minimum input is" << endl;
- cout << min << endl;
- } // second arithmetic formula
How many sets of data will be entered?
20
Please begin entering data set.
Enter -777 to indicate you are done with this set.
20
20
Please begin entering data set.
Enter -777 to indicate you are done with this set.
20
20
Please begin entering data set.
Enter -777 to indicate you are done with this set.
20
20
Please begin entering data set.
Enter -777 to indicate you are done with this set.
it would keep saying the please begin entering data set...
I tried multiple of ways to improve this, however, the condition of my program began worse...
been doing this seen my C++ class in University since 4:30 PM till right now 12:07 PM, can someone please help me