In C++ Can someone please check if this program compiles and runs correctly? If
ID: 3880103 • Letter: I
Question
In C++
Can someone please check if this program compiles and runs correctly? If it does not, can you please show me the correct solution?
Assignment:
Write a program that displays the following information about your career objective.
• Your name
• Your major
• What your ideal job would be like
• Three schools to which you are considering transferring
• What you consider the greatest impediments you might have in reaching your goal
• What you plan to do to succeed in achieving your goal
Use a menu and give the user the option to select the information they want to see. For example:
Joe Dokes' Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go to
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
Clicking Q ends the program.
Write separate functions for each of the five options.
Make sure the program only accepts M, J, S, I, G and Q, (upper and lower case letters), that validation prevents the user from entering an invalid character.
Write the program using a text editor. Compile the program using the command prompt and save as a text file with the .cpp extension. Submit the .cpp file, do not submit the .exe file.
My code:
#include <iostream>
using namespace std;
void major() {
cout << "Major" << endl;
}
void job() {
cout << "Job" << endl;
}
void schools() {
cout << "School 1, School 2, and School 3" << endl;
}
void impediments () {
cout << "Impediments" << endl;
}
void goal () {
cout << "Goals" << endl;
}
int main()
{
char userChar;
do {
cout << "John's Career Pathway Plan" << endl;
cout << "Choose an option: " << endl;
cout << " M - Major" << endl;
cout << " J - My ideal job" << endl;
cout << " S - Schools I'd like to go" << endl;
cout << " I - Impediments I face" << endl;
cout << " G - How I plan to reach my goals" << endl;
cout << " Q - Quit" << endl;
cin >> userChar;
switch (userChar) {
case 'M': case 'm' :
major();
break;
case 'J': case 'j' :
job();
break;
case 'S': case 's' :
schools();
break;
case 'I': case 'i' :
impediments();
break;
case 'G': case 'g' :
goals();
break;
case 'Q' : case 'q' :
cout << "Program ended." << endl;
return 0;
default :
cout << "Invalid option entered." << endl;
break;
}
} while ((userChar != 'q' || userChar != 'Q'));
return 0;
}
Explanation / Answer
#include <iostream>
using namespace std;
void major() {
cout << "Major" << endl;
}
void job() {
cout << "Job" << endl;
}
void schools() {
cout << "School 1, School 2, and School 3" << endl;
}
void impediments () {
cout << "Impediments" << endl;
}
void goal () {
cout << "Goals" << endl;
}
int main()
{
char userChar;
do {
cout << "John's Career Pathway Plan" << endl;
cout << "Choose an option: " << endl;
cout << " M - Major" << endl;
cout << " J - My ideal job" << endl;
cout << " S - Schools I'd like to go" << endl;
cout << " I - Impediments I face" << endl;
cout << " G - How I plan to reach my goals" << endl;
cout << " Q - Quit" << endl;
cin >> userChar;
switch (userChar) {
case 'M': case 'm' :
major();
break;
case 'J': case 'j' :
job();
break;
case 'S': case 's' :
schools();
break;
case 'I': case 'i' :
impediments();
break;
case 'G': case 'g' :
//goals(); error only,....everything else is fine...
goal();
break;
case 'Q' : case 'q' :
cout << "Program ended." << endl;
return 0;
default :
cout << "Invalid option entered." << endl;
break;
}
} while ((userChar != 'q' || userChar != 'Q'));
return 0;
}
output:
John's Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
m
Major
John's Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
j
Job
John's Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
s
School 1, School 2, and School 3
John's Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
i
Impediments
John's Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
g
Goals
John's Career Pathway Plan
Choose an option:
M - Major
J - My ideal job
S - Schools I'd like to go
I - Impediments I face
G - How I plan to reach my goals
Q - Quit
q
Program ended.
Process exited normally.
Press any key to continue . . .