Help me with this task please

input : 325
output : 3332255555

i was trying for so long but i cant get the right code ... im out ... please can someone do it ? im absolutely angry because its not hard. please.
int i = a - '0'; // '0' = 0
how are input and output related?
how are input and output related?

Can't you obviously see?
Repeat the number for it's value times.
string s;
cin >> s; // 325

now, print s[i] i times.
std::string s;std::cin>>s;for(auto t: s)for(int i=0;i<t-'0';++i)std::cout<<t;
Edit: whoops, a reference to the char is unnecessary...
Last edited on
can someone give me whole code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;

int main(){

	string wholeNumber;

	cin >> wholeNumber;
	
	for (auto num : wholeNumber){

		for (int i = 0; i < num - '0'; ++i)
		{
			cout << num;
		}
	}
	
	system("PAUSE");
}
Last edited on
This isn't supposed to be a "please do my homework" forum :D
bugbyte its not homework i code cuz i love it its my hobby i code for some months but sometimes i have problems so i cant do an easy task i could get point how to code exactly this and also what is auto num : ?
For 'auto' you will require to enable C++11 with your compiler (if not happened already).
It basically finds the Type for you. You could also write:
for(char num : wholeNumber) ...
In that case, sorry for jumping to conclusions.
Topic archived. No new replies allowed.