+ 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!? */
10 Réponses
+ 7
Thx @Julio I will see if it work...... Thx again. 😊😊😊😊😊
+ 6
Thx @luka but I make mistake my array doesn't have only 1 element.
+ 6
Please show me the correct code with descriptions.
+ 6
@luka I tried it but doesn't work correctly
+ 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.
+ 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.
+ 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;
}
+ 6
Hi friend . (surprise) .. My Code is now public please see it.
Include your name in it.
https://code.sololearn.com/cjNOwm9Q0vt3/?ref=app
+ 5
Thx @luka..... I will add your name as verifier in my next code. 😊😊😊😊😊
+ 4
@luka change if (s.length()>3) by if (s.length() -3 != 0)