Hello, I just finished the following code. I would like to know if it's ok so far.
Pseudocode
Code:Function main Pass In: nothing Do Call: clear_m Display "Welcome to the Fun Program." Display "Select from the menu." Display a blank line. Display "A gets Counting Loop." Display "B gets Impossible." Display "C gets Missing Item." Display "D gets Odd or Even." Display "E gets Poem." Display a blank line. Display "Q quits the program." Display a blank line. Display "Enter the letter of your choice.". Display "Then hit the enter key.". Display a blank line. Display "Your choice: --> ". Get the response for user_choice from the keyboard Case of user_choice 'A' Call: counting_loop 'B' Call: impossible 'C' Call: missing_item 'D' Call: odd_even 'E' Call: poem Endcase While user_choice not equal to 'Q' Pass Out: zero to the OS Endfunction ******************** Function counting_loop Pass In: nothing For x starts at 0, x < 5, increment x Display "Are we having fun?" Endfor Call: pause_m Pass Out: nothing Endfuction ******************** Function impossible Pass In: nothing Display "The repeat until loop is impossible in C++." Call: pause_m Pass Out: nothing Endfuction ******************** Function missing_item Pass In: nothing Display "This program is missing only the while loop." Call: pause_m Pass Out: nothing Endfuction ******************** Function odd_even Pass In: nothing Display a message asking user for an integer value Get the user_integer from the keyboard If user_integer modulus 2 Display "Your number was odd." Else Display "Your number was even." Endif Call: pause_m Pass Out: nothing Endfuction ******************** Function poem Pass In: nothing Display a 4 line poem Call: pause_m Pass Out: nothing Endfuction ******************** clear_m and pause_m are functions defined in the udst_monitor.h
Code
Code:// Headers and Other Technical Items #include <iostream> using namespace std; #include "C:\\Dev-Cpp\\user_library\\udst_monitor.h" // Function Prototypes void clear_m (void); void counting_loop (void); void impossible(void); void missing_item(void); void odd_even(void); void poem(void); void pause_m(void); // Variables char user_choice; int x; int user_integer; //****************************************************** // main //****************************************************** int main(void) { clear_m (); cout << "\nWelcome to the Fun Program "; cout << "\nSelect from the menu. "; cout << "\n "; cout << "\nA gets Counting Loop. "; cout << "\nB gets Impossible. "; cout << "\nC gets Missing Item. "; cout << "\nD gets Odd or Even. "; cout << "\nE gets Poem. "; cout << "\n "; cout << "\nQ quits the program. "; cout << "\nEnter the letter of your choice. "; cout << "\nThen hit the enter key. "; cout << "\n "; cout << "\nYour choice: "; cin >> user_choice; switch (user_choice) { case 'A': counting_loop(); break; case 'B': impossible(); break; case 'C': missing_item(); break; case 'D': odd_even(); break; case 'E': poem(); } while (user_choice != 'Q') return 0; } //****************************************************** // counting_loop //****************************************************** void counting_loop (void) { for (x = 0; x < 5;) { cout << "\nAre we having fun? "; x++; } pause_m(); } //****************************************************** // Impossible //****************************************************** void impossible(void) { cout <<"\nThe repeat until loop is impossible in C++. "; pause_m(); } //****************************************************** // missing_item //****************************************************** void missing_item(void) { cout << "\nThis program is missing only the while loop. "; pause_m(); } //****************************************************** // odd_even //****************************************************** void odd_even(void) { cout << "\nPlease enter an integer. --->: "; cin >> user_integer; if (user_integer % 2) { cout <<"\nYour number was odd. "; } else { cout <<"\nYour number was even. "; } pause_m (); } //****************************************************** // poem //****************************************************** void poem(void) { cout << "\nA comp sci exam and such a long lab must I do, "; cout << "\nOn a six-final-exam-ridden week, "; cout << "\nWaiting for me at my chiropractic 'schooo', "; cout << "\nNonetheless, I press on -- without a squeak. "; pause_m (); }
I hope everything is ok. Is that a good way to do it?




Reply With Quote