Can anyone correct this for me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone correct this for me?

#include <iostream> #include <string> using namespace std; int main() //take user input //use long to accomodate 999 billion long n; cout << "Enter the number:"; cin >> n; //preparing output string s; while{ if (n >1000){ //no need for commas s = to_string(n) + s; break; } else { //get the remainder with 1000 s = "," + to_string(n%1000) + s; n /= 1000; } } cout << "number with commas:" << s << endl; }

15th Jun 2020, 8:12 PM
Bhreezy Brains
Bhreezy Brains - avatar
7 Answers
+ 5
U missed curly brac after main function put curly brac then try to run your code . Its a very small mistake first try to solve errors by self. If u unable to solve then post here. Hope u understood thanks.
16th Jun 2020, 8:39 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Where is the condition for your while loop.... While(Boolean expression){ Statement... }
16th Jun 2020, 7:11 PM
MILES CODER
MILES CODER - avatar
0
You are missing a '{' after main()
15th Jun 2020, 8:42 PM
Calbaros
Calbaros - avatar
0
It's still not running
15th Jun 2020, 9:07 PM
Bhreezy Brains
Bhreezy Brains - avatar
0
Could you post the code here?
15th Jun 2020, 9:13 PM
Calbaros
Calbaros - avatar
0
#include <iostream> #include <string> using namespace std; int main() //take user input //use long to accomodate 999 billion long n; cout << "Enter the number:"; cin >> n; //preparing output string s; while{ if (n >1000){ //no need for commas s = to_string(n) + s; break; } else { //get the remainder with 1000 s = "," + to_string(n%1000) + s; n /= 1000; } } cout << "number with commas:" << s << endl; }
15th Jun 2020, 9:27 PM
Bhreezy Brains
Bhreezy Brains - avatar
0
Thanks
16th Jun 2020, 8:51 AM
Bhreezy Brains
Bhreezy Brains - avatar