0

i am try to solve ex7 from chapter 2 (Prata's c++ primer plus)

The task is:

Write a program that asks the user to enter an hour value and a minute value.The main() function should then pass these two values to a type void function that displays the two values in the format shown in the following sample run: Enter the number of hours: 9 Enter the number of minutes: 28 Time: 9:28

My Code is :

#include <iostream>


void hours(int);
void minutes(int);


int main()

{
    using namespace std;
    int hhrs;
    int mnts;
    cout << "Enter hours: "; cin >> hhrs; cout << endl;
    cout << "Enter minutes: "; cin >> mnts; cout << endl;

    hours(hhrs);
    minutes(mnts);

    cout << "Time is: " << hours << ":" << minutes << endl;

    cin.get();
    cin.get();
    return 0;
}

void hours(int n)
{
    using namespace std;
    cout << n;
}

void miutes(int m)
{
    using namespace std;
    cout << m;
}

Errors are :

1) Error 1 error LNK2019: unresolved external symbol "void __cdecl minutes(int)" (?minutes@@YAXH@Z) referenced in function _main G:\~DEV#c++\he\he\Source.obj

2) Error 2 error LNK1120: 1 unresolved externals G:\~DEV#c++\he\Debug\he.exe 1

Jongware
  • 22,200
  • 8
  • 54
  • 100
andynoir
  • 25
  • 1
  • 6
  • 1
    You spelled `miutes` wrong – Brian Rasmussen Dec 20 '13 at 18:25
  • instead of `using namespace std;` in every scope, you can put it at the begin of the program. But [it's a bad practice?](https://stackoverflow.com/q/1452721/995714) and you should use `using std::cout` instead – phuclv Aug 29 '18 at 15:07

3 Answers3

4

In addition to your misspelling (miutes instead of minutes), you also are not doing what the problem is asking:

Write a program that asks the user to enter an hour value and a minute value.The main() function should then pass these two values to a type void function that displays the two values in the format shown in the following sample run: Enter the number of hours: 9 Enter the number of minutes: 28 Time: 9:28

That is asking you to input 2 values, and pass those values to a single function that will print them in the desired format.

Zac Howland
  • 15,777
  • 1
  • 26
  • 42
2

You misspelt minutes in the function definition.

void miutes(int m)
     ^^^^^^

Note that your hours and minutes functions do exactly the same thing. There's no point having both of them. You could have a single function called print. However, since all they do is call another single function (cout.operator<<), I would just get rid of them all together. Just do cout << hhrs and cout << mnts when you need it. Your problem does require you to move the printing of both the hours and minutes into a function though.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
0

Apart from the spelling mistake in void miutes(int m), the logic does not require two seperate functions to call.

Also if you check the below line:

cout << "Time is: " << hours << ":" << minutes << endl;

Here "hours" and "minutes" will always evaluate as True. So eventually it will show 1:1 in output, not 9:28 (as per your input).

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
arin1405
  • 677
  • 1
  • 7
  • 18