| Natalyias77 (10) | |
|
I am writing a program for school that is supposed to take an array and print its contents. I have reached out to the teacher but I don't know when I will hear back. I keep getting errors: Errors: 1>------ Build started: Project: Assignment 9 - Array Homework, Configuration: Debug Win32 ------ 1> Assignment 9 - Array Homework.cpp 1>Assignment 9 - Array Homework.obj : error LNK2028: unresolved token (0A00031F) "void __cdecl print_integers(int * const,int)" (?print_integers@@$$FYAXQAHH@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) 1>Assignment 9 - Array Homework.obj : error LNK2019: unresolved external symbol "void __cdecl print_integers(int * const,int)" (?print_integers@@$$FYAXQAHH@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) 1>C:\Users\sxc879\documents\visual studio 2010\Projects\Assignment 9 - Array Homework\Debug\Assignment 9 - Array Homework.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Here is my program: // Assignment 9 - Array Homework.cpp : main project file. #include "stdafx.h" #include <iostream> using namespace std; const int ARRAY_SIZE = 5; //int round (float x); // rounds any float to the nearest int void print_integers(int aRay[], int size); //prints out the rounded value of every element of the array int main() { int listA[ARRAY_SIZE] = {0}; cout << "List A elements are: "; print_integers(listA, ARRAY_SIZE); cout << endl; system ("pause"); return 0; } | |
|
|
|
| Moschops (5956) | |||
|
You have to write the function print_integers. Here's something to get you started:
| |||
|
|
|||
| Natalyias77 (10) | |
|
Thank you. This is my first time with arrays and functions. The book I am using was not clear on calling an array as a function. So I have updated my code but I can't get the function to print. It will call the function, but not print out my array. I just want to work on this piece then I will work on rounding. Thoughts? Plus how do I comment out my code? void print_integers(int aRay[], int size) { int index; for(index = 0; index < size; index++) cout << "Rounded value of every element: " << aRay[index] << " " ; } | |
|
Last edited on
|
|
| Marcos Modenesi (26) | |||
What kind of truoble do you get? compiler messages?
I think you were missing a couple of {}, but I´m not sure. To comment a code, use //comment comment comment...(to the end of line) or /*comment comment comment*/ Try posting your code using the code format button, at the right of the text input window. | |||
|
|
|||
| Natalyias77 (10) | |||
|
So after working on this all day this is what I came up with. I have gotten closer to the end result but not quite yet there. What I now need to do is to call function round . The code for this function is supposed to take the array of float (I know I have it all as int right now) and round it off, returning the value to the nearest integer. No C++ libraries. But so far this is what I have. It runs as I need it to. Any ideas on how to code to round off without C++ libraries? Thanks for the hint on posting code :-)
| |||
|
|
|||
| LowestOne (767) | |||
Add an amount to the float that will make the float be the right value when it is trunkated:
| |||
|
|
|||