| TMix (1) | |
|
Hello everyone, I'm working on debugging some code (this is a homework question, but I only want to be guided in the right direction) and I can't seem to figure out what I'm supposed to be doing, as there isn't much info to go on. Here's the original code. // Debug 4-3 // Function displays course information // instructor defaults to Staff // enrollment defualts to 30 #include<iostream.h> #include<conio.h> void main() { void displayCourseInfo(char instructor[] = "Staff", int enrollment = 30, char course[]); displayCourseInfo("ENG101"); displayCourseInfo("Bossert", "PSY151"); displayCourseInfo("Dykeman", 24, "CIS200"); getch(); } void displayCourseInfo(char course[], char instructor[], int enrollment) { cout<<course<<" taught by "<<instructor<<" enrollment "<<enrollment<<endl; } The original code is in C format i believe, but I'm supposed to fix up the code and make it work in C++. Here's what I've managed so far: // Debug 4-3 // Function displays course information // instructor defaults to Staff // enrollment defaults to 30 #include <iostream> #include <conio.h> using namespace std; void displayCourseInfo(char course[], char instructor[], int enrollment) { cout<<course<<" taught by "<<instructor<<" enrollment "<<enrollment<<endl; } int main() { displayCourseInfo(char course[], char instructor[] = "Staff", int enrollment = 30); displayCourseInfo("ENG101"); displayCourseInfo("PSY151", "Bossert"); displayCourseInfo("CIS200", "Dykeman", 24); system("pause"); return 0; } I'm at a loss as to how the program is actually supposed to display the course information. All I have to go on are the comments at the top of the program. Any hints would be greatly appreciated. | |
|
|
|
| SamuelAdams (319) | |
|
consider 2 approaches #1, comment out everything that doesn't work and add in one line at a time until you get a working code. #2 Here is what I would do. Forget about debugging this code for a minute. It's very small, so should take you no time to re-write. Think about getting the data from main() and passing it to this function. Use it as a guideline. I would start http://www.cplusplus.com/doc/tutorial/functions2/ | |
|
|
|