Hey! I am a beginner in C++ and I am trying to build a code where the count value input by the user will decrement (if input value is 10, then: 10,9,8,7,6,5,4,3,2,1) till the condition is met. And this count will be displayed till the input iteration value becomes 0.
But the code does not work and supposedly does not take the for (i) for loop. and thus displays "a" only one time.
What am i doing wrong?
[code]
#include <iostream>
using namespace std;
int main()
{
int a,i;
cout << "Enter the count value: ";
cin >> a;
cout << "Enter the iteration value: ";
cin >> i;
{
for (i;i>0; i--)
{
for (a; a>0; a--)
{
cout << a << ", ";
}
}
}
return 0;
}
#include <iostream>
int main()
{
int cnt = 0 ;
std::cout << "enter count value: " ;
std::cin >> cnt ;
int iterations = 0 ;
std::cout << "enter iteration value: " ;
std::cin >> iterations ;
for( int i = 0 ; i < iterations ; ++i ) // repeat iteration number of times
{
// print a comma after every number other than 1
for( int j = cnt ; j > 1 ; --j ) std::cout << j << ", " ;
if( cnt > 0 ) std::cout << "1\n" ; // print 1 and a new line
}
// note that if iterations < 1, nothing is printed (the body of the outer loop does not execute)
// note that if cnt < 1, nothing is printed
// (the body of the inner loop does not execute, and printing "1\n" at the end is skipped)
}