0

Here's my code I am new to stack exchange so kindly ignore any silly mistakes when I try to compile this program it says that the array is ambiguous I really don't know what to do please help

#include <array>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
char array[2];
void format(int number, int width,char* array);
int main(void)
{
    int number,width;
    cout<<"write a number:"<<endl;
    cin>>number;
    cout<<"write width:"<<endl;
    cin>>width;
    format(number,width,char(&array)[2]);
}
void format(int number, int width,char* array)
{
    int numofzeros;
    int length = (int)(log10(number)+1);
    numofzeros=width-length;
    if(width<length)
    {
        cout<<number<<endl;
    }
}
  • `#include ` probably doesn't do what you think it does. – πάντα ῥεῖ Dec 06 '20 at 12:30
  • Prime example why [`using namespace std` is bad practice](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). You called your variable `array`, but there is also `std::array` which no lives in the global namespace. – Lukas-T Dec 06 '20 at 12:30
  • The other errors are `char(&array)[2]` where I honestly don't know what it's supposed to do. Then why is `array` even passed to `format`? It's not used there. In fact it isn't use _anywhere_, but ok, maybe you want to expand the code in the future. A real error is the use of uninitilized `numofzeros`. – Lukas-T Dec 06 '20 at 12:33

0 Answers0