+ 8

Please show me my fault in this C++ code?

#include <iostream> using namespace std; void num(int s){ switch (s){ case 0: cout<<"o"<<endl; break ; case 1: cout<<"oo"<<endl; break ; case 2: cout<<"ooo"<<endl; break ; } }; int main(){ int n[3]; getline(cin,n); //cout<<sizeof(n); for(int i=0;i<sizeof(n);i++) { num(n[i]); } return 0; } /*I want for exemple when user enter the number "562" the main function must call num function 3 times that way: num[5]; num[6]; num[2]; How!? */

31st May 2017, 4:03 AM
BENOTMANE
BENOTMANE - avatar
10 Answers
+ 7
Thx @Julio I will see if it work...... Thx again. 😊😊😊😊😊
31st May 2017, 8:24 AM
BENOTMANE
BENOTMANE - avatar
+ 6
Thx @luka but I make mistake my array doesn't have only 1 element.
31st May 2017, 4:18 AM
BENOTMANE
BENOTMANE - avatar
+ 6
Please show me the correct code with descriptions.
31st May 2017, 4:21 AM
BENOTMANE
BENOTMANE - avatar
+ 6
@luka I tried it but doesn't work correctly
31st May 2017, 4:37 AM
BENOTMANE
BENOTMANE - avatar
+ 6
I want for exemple when user enter the number "562" the main function must call num function 3 times that way: num[5]; num[6]; num[2]; How can I do that.
31st May 2017, 4:40 AM
BENOTMANE
BENOTMANE - avatar
+ 6
No @luka, I want the user write like that 129 only one number and I will manipulate the number in the program and make it like that 1 2 9 And send a call of function for each element like that : num[1]; num[2]; num[9]; Then the switch will execute for each element.
31st May 2017, 5:14 AM
BENOTMANE
BENOTMANE - avatar
+ 6
int main(){ int n,c,*arr,rest,i; cout<<"Number:"; cin>>n; cout<<endl<<"Number of digits:"; cin>>c; arr = new int[i = c]; while(n){ rest = n % 10; arr[--i] = rest; n = n / 10; } for(i = 0;i<c;i++) num(arr[i]);//Function implemented by you return 0; }
31st May 2017, 8:20 AM
Julio Cesar Rosales Rodriguez
Julio Cesar Rosales Rodriguez - avatar
+ 6
Hi friend . (surprise) .. My Code is now public please see it. Include your name in it. https://code.sololearn.com/cjNOwm9Q0vt3/?ref=app
2nd Jun 2017, 4:02 PM
BENOTMANE
BENOTMANE - avatar
+ 5
Thx @luka..... I will add your name as verifier in my next code. 😊😊😊😊😊
31st May 2017, 4:32 AM
BENOTMANE
BENOTMANE - avatar
+ 4
@luka change if (s.length()>3) by if (s.length() -3 != 0)
31st May 2017, 6:17 PM
Julio Cesar Rosales Rodriguez
Julio Cesar Rosales Rodriguez - avatar