please help

Jan 20, 2013 at 12:50am
i'm new to this program C++.
write a program that reads an integer and breaks it into a sequence of individual digits. for example the input 16384 is displayed as 1 6 3 8 4.

please help me edit and add some code to this.
Thanks a lot.

#include <iostream>
#include <string>

using namespace std;

int main()
{
cout << "Enter a five-digit number: ";
cin >> number;

cout << number / 10000 << " ";
number = number % 10000;
cout << number / 1000 << " ";
number = number % 1000;
cout << number / 100 << " ";
number = number % 100;
cout << number / 10 << " ";
number = number % 10;
cout << number << endl;
return 0;
}
Last edited on Jan 30, 2013 at 1:42am
Jan 20, 2013 at 1:11am
The character '\' is used as an escape character in string literals for characters not represented visually, like newline '\n' or carriage return '\r'.

You need to type "\\" to use backslashes or else it thinks you are using it as an escape character.

cout << " / \\ " << endl;
Outputs:
" / \ "
Last edited on Jan 20, 2013 at 1:12am
Jan 20, 2013 at 1:55am
Thanks branflakes but when I re-edited I couldn't compile it. Could u please help me out. Thanks a lot
Jan 20, 2013 at 2:10am
Really? It compiled fine with gcc-4.3.4.

What compiler are you using?
Jan 20, 2013 at 2:16am
I'm using visual studio 2010 for my class
Jan 20, 2013 at 2:19am
oky just use your brain if \\ changes to \ and you need 2, so do this \\\\
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;

int main()
{
cout << " / \\\\ "<< endl;
cout << " / \\\\"<< endl;
cout << " +----+ " << endl;
cout << " | .-. | "<< endl;
cout << " | | | | "<< endl;
cout << " +-+-++ "<<endl;
return 0;
}


example http://ideone.com/qDMdK9
Last edited on Jan 20, 2013 at 2:26am
Jan 20, 2013 at 2:44am
I'm using visual studio 2010 for my class

It should compile then. You aren't using a precompiled header are you? Then you'd need to include "stdafx.h"

What errors are you getting?
Topic archived. No new replies allowed.