1

I've been looking all over online and have no idea what the instructor means, and he doesn't like replying until 4-5 days later. Very quick and brief overview of the project: -Create three files in Putty Unix, (main.cpp - provided by instructor, functions.cpp, functions.h) -Purpose: calculate average of 2 integers input by user, lists GCM, lists LCM

I'm most likely fine with GCM and LCM, but the average part is what I'm stuck on. Instructions said to uncomment the call to doAverage() in main. There is no doAverage() in the main.cpp he provided though, and I've tried removing the doAverage under case 3, and program still does not work. Am I missing something?

main.cpp code:

#include <iostream>
#include "functions.h"

using namespace std;

void getValues(int& x,int& y) {
cout << "Enter the first integer: ";
cin >> x;
cout << "Enter the second integer: ";
cin >> y;
}

int main() {

 int choice;
 bool done = false;
 int x,y;

 cout << "Welcome to the math functionator!" << endl << endl;

 do {
cout << "1) GCD" << endl;
cout << "2) LCM" << endl;
cout << "3) average" << endl;
cout << "0) quit" << endl;
cout << "Enter choice: ";

cin >> choice;

   if (choice != 0) {
    getValues(x,y);
   }

   switch (choice) {
    case 1:

        //doGCD(x,y);
        break;
    case 2:
        //doLCM(x,y);
        break;
    case 3:

    case 0:
        done = true;
  }
  } while (!done);

 cout << "Bye" << endl;

  return(0);
}

functions.cpp code:

#include <iostream>
using namespace std;
void doAverage(int x, int y);
{
int sum = x+y;
int average = sum/2;

cout << "Average of " << x << " and " << y << " is " << average << endl;
}

functions.h code:

void doAverage(int x, int y);

The main.cpp was provided by the instructor, and the code from functions.cpp as well as functions.h is also provided from instructor. Instructions said to uncomment doAverage from main, but I thought you only uncomment if there are # or ./, etc...

Andy Le
  • 31
  • 1
  • 6
  • 2
    ok... sounds like there should be `doAverage(x, y);` in `main()` under `case 3:` – kmdreko May 13 '16 at 20:25
  • Whoops, I forgot I erased it, and didnt put it back yet. With it there, it didn't work and instructions said to uncomment doAverage, but there was no #, etc... so I figured erasing that was the only thing to do. – Andy Le May 13 '16 at 20:40

1 Answers1

2

I think there is a trivial error in the main.cpp that you were provided with. case 3 should have looked like:

        case 3:
            //doAverage(x,y);
            break;

To comment-out a piece of code is to surround it with /* ... */ or to precede it with //. To uncomment it, is to remove the comment markers. In the supplied code above, the call to doAverage is commented out. You need to remove the comment characters.

Also, beat your instructor over the head with the answers to this question, and tell him to stop misleading you with using namespace std;

Community
  • 1
  • 1
  • Yeah! Sorry about that, I erased it in attempt to try and get the program to work. - That was in the original main.cpp. I couldn't think of what to do when the instruction said to uncomment doAverage so I tried erasing that (didn't do anything) so I put it back. – Andy Le May 13 '16 at 21:01
  • Thank you! Was reading back and fourth through our text book and whatnot, had explanations of /* .... */ and #, but mentioned nothing of //. – Andy Le May 13 '16 at 21:09
  • Note that # does not introduce a comment in C++ (or C). (You can use `#if 0 ... #endif` to achieve a similar affect.) – Martin Bonner supports Monica May 14 '16 at 07:00