Hello people, this is my first time using this site so cut me some slack if I have trouble. I am in currently Foundations and Computer Programming II learning how to use C++ in more advance ways. I been given my first assignment and I've already came across an error that I don't know how to fix. The error is "C4700: uninitialized local variable 'n2' used" and here is what I have.
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include "multiply.h"
usingnamespace std;
int main()
{
//lab1 part1, I am writing a program to multiply 2 numbers.
int n1, n2;
cout << "Enter in 2 numbers and I will multiply them" << endl;
cin >> n1, n2;
multiply(n1, n2);
system("pause");
return 0;
}
multiply.h
void multiply(int, int);
multiply.cpp
1 2 3 4 5 6 7 8
#include <iostream>
#include "multiply.h"
usingnamespace std;
void multiply(int& n1, int n2)
{
n1 = n1*n2;
cout << "The product of those 2 numbers is " << n1 << endl;
}
Can anyone please help me figure out what I am doing wrong.
Thank you for that tip Tarik, but now I have come across 2 more errors when I made that change. Both of them are error "LNK2019: unresolved external symbol."
One error says 'WinMain@16 referenced in function "int_cdel invoke_main(void)" (? invoke_main@@YAHXZ)'
The other one says '"void_decl multiply(int,int)" (?multiply@@YAXHH@Z) referenced in function_main'
I think this might be more of a file error, but I'm not sure. I should probably start another forum.
This means that you've selected the wrong kind of project. You're using Visual Studio version something; if you want to use a main function, you needed to create a simple, plain console project.