Hello, this is my most difficult assignment yet. Quick Disclaimer: I am a student taking intro to programming. I have some experience in Python because that's what I'll be using/have used in the Geographic Information Systems industry. I recently went back to school to make my knowledge in GIS official.
I've made plenty of headway, but I've run into several problems. I've read several threads in this forum that were related and they could only provide so much guidance. I also read through the chapters, got help from a friend who writes code for a living (unfortunately not in C++) and I've gone over the tutorials on this web site.
The solution eludes me, but I know I'm close.
Below is my code thus far. I put in comments to help show you where I need more guidance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
// Headers and Other Technical Items
#include <iostream>
using namespace std;
#include "C:\\Users\\Alan\\Cpp_Software_Download\\Dev-Cpp\\user_library\\udst_monitor.h"
// Variables
char user_choice;
//int user_integer; //This is for a future function not yet written.
int x;
// Function prototypes
void counting_loop(){ //void is the only type that didn't return an
//error
cout << ".counting_loop"; //This is a test to see if my call functions work.
} //When I inserted my real counting loop here it
//didn't work.
void impossible(void){
cout << ".impossible"; //I haven't tried to get the rest of these to
//work yet.
}
void missing_item(void){
cout << ".missing_item";
}
void odd_even(void){
cout << ".odd_even";
}
void poem(void){
cout << ".poem";
}
//******************************************************
// main
//******************************************************
int main(void) //Not sure if I should define my functions below or above
//this point.
{
//******************************************************
// do while
//******************************************************
//clear_m(); If I clear here it is ineffective.
do
//clear_m(); If I clear here I get an error.
{
//clear_m(); If I clear here the screen clears my answer before I can
//read it.
cout << "Welcome 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 << "\n ";
cout << "\nEnter the letter of your choice.";
cout << "\nThen hit the enter key.";
cout << "\n ";
cout << "\nYour choice: -----> ";
cin >> user_choice;
clear_m(); //If I clear here I get the answer and the Welcome message again.
//Best outcome so far, but not what I want.
//******************************************************
// case
//******************************************************
switch (user_choice)
{
case 'A': counting_loop();
cout << "\n\n";
break;
pause_m ();
return 0;
case 'B': impossible();
cout << "\n\n";
break;
pause_m ();
return 0;
case 'C': missing_item();
cout << "\n\n";
break;
pause_m ();
return 0;
case 'D': odd_even();
cout << "\n\n";
break;
pause_m ();
return 0;
case 'E': poem();
cout << "\n\n";
break;
pause_m ();
return 0;
}
//******************************************************
// counting loop: This is where my functions were originally.
//******************************************************
//counting_looop();
//for (x = 0; x < 5; x++)
//{
//cout << "\nAre we having fun?";
//}
//pause_m();
//return 0;
//******************************************************
// impossible loop: This has yet to work at all.
// I am tempted to use a nested if function.
//******************************************************
//do
//{
//cout << "\nThe repeat until looop is impossible in C++.";
//}
//while (user_choice == 'B');
//pause_m();
//return 0;
}
while (user_choice != 'Q');
pause_m();
return 0;
}
//******************************************************
// End of Program
//******************************************************
|
If you run this, you can delete comment slashes to see how I've played with this. I've structured this the way I have to follow the pseudocode I was given. If I stray from that too far, I'll lose points.
I will submit the pseudocode if it helps you understand why I wrote this code the way I did.
Here is a basic outline:
Function main
Pass in nothing
Do
Call clear screen
All the display
User input
Case of user choice A-E
Endcase
While Q not equal to Q
Pass out zero
Endfunction
Then the five functions are listed separately below. I won't list them here because they seem easy/I've done them before. They use the three variables listed.
So to summarize my questions:
How should I clear the screen to follow the pseudocode? (lines 59 & 80)
It seems functions in C++ must be written in a certain order or there will be errors. Why do my test couts work, but when I insert the actual functions they get errors?
Should any of my defined functions include parameters? I simply declared them and call them in my switch case function.
I know this was a long post, but I wanted to be thorough. Thank you for reading.