'For command, print numbers up to 5 that are divisible by a number which the user enters

I ran into a task that says to make a program that told me to print numbers up to 5 that are divisible by the number which user enters with the "for" command.

#include<iostream>

using namespace std;

int main{


    int a;
    
    cout<<"Type in a:  "<<endl;
    cin>>a;
    for(int i;i<6;i++){
    
    if((a%1)==0)
        cout<<i<<endl;
    
    else if((a%2)==0)
        cout<<i<<endl;
    
    else if((a%3)==0)
        cout<<i<<endl;
        
    
    else if((a%4)==0)
        cout<<i<<endl;
        
    else if((a%5))
        cout<<i<<endl;
    
    cout<<i<<endl;
}
    
    return 0;
    
}
c++


Solution 1:[1]

First, you need to initialize i in

for(int i;i<6;i++){

Like:

for(int i=0;i<6;i++){

Second, you don't really need to test

if((a%1)==0)

It will always be 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vlad Feinstein