What error is in this code? I keep getting this error but can't find how to solve it. 'printValues (int, int&, int&, int&)' This is the code in c++: /* This program processes the bioryhthm of the users input based on the current date and their birthdate */ #include using namespace std; int daysAlive(); int numDaysReport(); void BioProcessed(int numDaysReport, int daysAlive); void calcValues(int numDaysReport, int&, int&, int&); void printValues(int, int&, int&, int&); int main(void) { int days = daysAlive(); int report = numDaysReport(); BioProcessed (report, days); return 0; } int daysAlive () { int d; cout << "How many days have you been alive? "; cin >> d; return d; } int numDaysReport () { int n; cout << "How many days would you like to be reported? "; cin >> n; return n; } void BioProcessed (int numDaysReport, int daysAlive) { cout << "This report is for someone who has been alive "; cout << daysAlive << endl; int physical; int emotional; int mental; for (int i = 0; i < numDaysReport; i++) { calcValues(daysAlive + i, physical, emotional, mental); printValues(daysAlive + i, physical, emotional, mental); } } void calcValues(int daysAlive, int& physical, int& emotional, int& mental) { physical = sin(2 * 3.14592 * daysAlive / 23.0) * 25 + 25; emotional = sin(2 * 3.14592 * daysAlive / 28.0) * 25 + 25; physical = sin(2 * 3.14592 * daysAlive / 33.0) * 25 + 25; } void printValues(int daysAlive, int physical, int emotional, int mental) { cout << "Day: " << daysAlive << "\t" << physical << "\t" << emotional << "\t" << mental << endl; string output = ".........................|........................."; output[physical] = 'P'; output[emotional] = 'E'; output[mental] = 'M'; cout << output <

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What error is in this code? I keep getting this error but can't find how to solve it. 'printValues (int, int&, int&, int&)'

This is the code in c++:

/*

This program processes the bioryhthm of the users input based on the current date and their birthdate
*/
#include <bits/stdc++.h>
using namespace std;

int daysAlive();
int numDaysReport();
void BioProcessed(int numDaysReport, int daysAlive);
void calcValues(int numDaysReport, int&, int&, int&);
void printValues(int, int&, int&, int&);

int main(void)
{
int days = daysAlive();
int report = numDaysReport();

BioProcessed (report, days);
return 0;
}

int daysAlive ()
{
int d;
cout << "How many days have you been alive? ";
cin >> d;

return d;
}
int numDaysReport ()
{
int n;
cout << "How many days would you like to be reported? ";
cin >> n;

return n;
}

void BioProcessed (int numDaysReport, int daysAlive)
{
cout << "This report is for someone who has been alive ";
cout << daysAlive << endl;
int physical;
int emotional;
int mental;
for (int i = 0; i < numDaysReport; i++)
{
calcValues(daysAlive + i, physical, emotional, mental);
printValues(daysAlive + i, physical, emotional, mental);
}

}

void calcValues(int daysAlive, int& physical, int& emotional, int& mental)
{
physical = sin(2 * 3.14592 * daysAlive / 23.0) * 25 + 25;
emotional = sin(2 * 3.14592 * daysAlive / 28.0) * 25 + 25;
physical = sin(2 * 3.14592 * daysAlive / 33.0) * 25 + 25;
}
void printValues(int daysAlive, int physical, int emotional, int mental)
{
cout << "Day: " << daysAlive << "\t" << physical << "\t" << emotional << "\t" << mental << endl;
string output = ".........................|.........................";
output[physical] = 'P';
output[emotional] = 'E';
output[mental] = 'M';
cout << output << endl;
}

### Understanding Linker Errors in C++: An Example

In this example, we explore a common linker error encountered in C++ programming. Let's dissect the error message received when compiling a C++ program.

#### Error Message

```
clang++-7 -pthread -std=c++17 -o main main.cpp
/tmp/main-35652e.o: In function `BioProcessed(int, int)':
main.cpp:(.text+0x174): undefined reference to `printValues(int, int&, int&, int&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
exit status 1
```

#### Explanation

1. **Command Invocation**:
   - `clang++-7 -pthread -std=c++17 -o main main.cpp`: This command attempts to compile the `main.cpp` file using the Clang compiler with C++17 standards and pthread support, outputting an executable named `main`.

2. **Undefined Reference Error**:
   - The error `undefined reference to 'printValues(int, int&, int&, int&)'` indicates that the linker cannot find the definition of the function `printValues` that is being called within the `BioProcessed` function in the program. It suggests that although `printValues` is declared, it likely lacks an actual function definition in any of the linked source files.

3. **Linker Command Failure**:
   - `clang: error: linker command failed with exit code 1`: The linker phase of compilation failed due to unresolved references, and an exit status of 1 signifies the error. The suggestion `(use -v to see invocation)` hints at using a verbose option to obtain additional details about the failure.

#### Possible Solutions

- **Ensure Function Definition**:
  - Verify that `printValues` is defined in a source file that is being compiled and linked.
  
- **Include Necessary Files**:
  - Check if you have included the correct source file or library where `printValues` is defined.

- **Check for Typos**:
  - Ensure there are no typographical errors in function declarations or definitions.

Understanding and resolving linker errors can be challenging, but carefully examining error messages and verifying code can guide you to the solution.
Transcribed Image Text:### Understanding Linker Errors in C++: An Example In this example, we explore a common linker error encountered in C++ programming. Let's dissect the error message received when compiling a C++ program. #### Error Message ``` clang++-7 -pthread -std=c++17 -o main main.cpp /tmp/main-35652e.o: In function `BioProcessed(int, int)': main.cpp:(.text+0x174): undefined reference to `printValues(int, int&, int&, int&)' clang: error: linker command failed with exit code 1 (use -v to see invocation) exit status 1 ``` #### Explanation 1. **Command Invocation**: - `clang++-7 -pthread -std=c++17 -o main main.cpp`: This command attempts to compile the `main.cpp` file using the Clang compiler with C++17 standards and pthread support, outputting an executable named `main`. 2. **Undefined Reference Error**: - The error `undefined reference to 'printValues(int, int&, int&, int&)'` indicates that the linker cannot find the definition of the function `printValues` that is being called within the `BioProcessed` function in the program. It suggests that although `printValues` is declared, it likely lacks an actual function definition in any of the linked source files. 3. **Linker Command Failure**: - `clang: error: linker command failed with exit code 1`: The linker phase of compilation failed due to unresolved references, and an exit status of 1 signifies the error. The suggestion `(use -v to see invocation)` hints at using a verbose option to obtain additional details about the failure. #### Possible Solutions - **Ensure Function Definition**: - Verify that `printValues` is defined in a source file that is being compiled and linked. - **Include Necessary Files**: - Check if you have included the correct source file or library where `printValues` is defined. - **Check for Typos**: - Ensure there are no typographical errors in function declarations or definitions. Understanding and resolving linker errors can be challenging, but carefully examining error messages and verifying code can guide you to the solution.
Expert Solution
Step 1

According to the question below the solution:

 

After fix the errors

 

Output:

Computer Science homework question answer, step 1, image 1

 

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education