Correct My Code :D
Go to solution
Solved by Mr_KoKa,
Your code is wrong cause you use "=" instead of "==" in your while, but even if you will use "==" it won't be good, cause you should use "!=", so after changing "=" into "!=" you're should be fine.
Edit: Your exercise says that after every number there should be a space, so I edited.
Your code with a fix:
#include <iostream>using namespace std;int main(){ int x,counter=0; cin>>x; while (counter != x) { cout<<x << ' '; counter++; } return 0;}
My code (works too, but uses for loop):
#include <iostream>int main() { int x; std::cin >> x; for(int i = 0; i < x; i++){ std::cout << x << ' '; } return 0;}
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now