Jump to content

Correct My Code :D

ichihgo
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;}

C++

 

WqQGmCU.jpg

#include <iostream>using namespace std;int main(){ int x,counter=0; cin>>x; while (counter=x) {     cout<<x;     counter++; }    return 0;}
Link to comment
Share on other sites

Link to post
Share on other sites

Sorry I can't answer, just wanted to drop in and say "C++, gross." However I did think C++ was the worst until now, 5 weeks into C#, and I hate this one even more! Good luck!

Black/Red Beast: CPU: i7 4790k Cooling: Hyper 212 Evo MB: MSI Z97 Gaming 5 GPU: MSI GTX 980 RAM: 16GB 1866 HyperFury X SSD: 256GB Samsung Evo 840

Link to comment
Share on other sites

Link to post
Share on other sites

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;}
Link to comment
Share on other sites

Link to post
Share on other sites

Dang it. Beaten to the punch again.

CPU Intel Core i7-4790K Motherboard ASUS Saberthooth Z97 Mark1 RAM Corsair Dominator Platinum 16GB @ 2133MHZ GPU 2 X MSI GeForce GTX GTX 980TI GAMING 6G SLI Case Phantex Enthoo Evolv ATX Storage Samsung 840 Pro Series 256GB / Western Digital Caviar Black 2TB PSU Corsair RM1000i Display Asus 4K PB287Q Cooling Noctua NF-A14 FLX & NF-F12 PWM /Thermaltake Water 3.0 Ultimate 360mm Keyboard Corsair K70 Mouse ROCCAT Kone XTD Sound Card Asus Xonar STX

Link to comment
Share on other sites

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×