6
I made a program that calculates Fibonacci numbers in X and Y using Z as an auxiliary.
When I pass the vector from the Fibonacci function to the function imprime
, she doesn’t print. I did a test by putting a cout
within the for
of the calculation and found that the error is precisely in the function imprime
, bearing in mind that the cout
in the calculation does everything exactly as it had to do. I suspect the problem is exactly in the for
of imprime
.
I believe this information will help: my role imprime
generates an error that I don’t know how to solve:
C4018 '<': Unsigned Mismatch
Program. h:
#pragma once
#ifndef __MEU_H_INCLUDED__
#define __MEU_H_INCLUDED__
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
void imprime(std::vector<int>& v);
void fibonacci(int x, int y, std::vector<int> fi, int numeroElementos);
#endif
cpp of implementation:
#include "stdafx.h"
#include "meu.h"
using std::cout;
using std::endl;
void imprime(std::vector<int>& v)
{
for(int x = 0; x < v.size(); x++)
cout << v[x];
}
void fibonacci(int x, int y, std::vector<int> fi, int numeroElementos)
{
int z = 0;
for (int b = 0; b <= numeroElementos; b++)
{
z = x + y;
fi.push_back(z);
x = y;
y = z;
}
}
Main.cpp :
#include "stdafx.h"
#include "meu.h"
int main()
{
int valor1 = 0;
int valor2 = 0;
int NumeroElementos = 0;
std::vector<int> numeros;
while (std::cin >> valor1 >> valor2 >> NumeroElementos) {
fibonacci(valor1, valor2, numeros, NumeroElementos);
imprime(numeros);
}
system("pause");
return 0;
}