+ 1

There is a string like this "The answers of polynominal are 5.5 ,4.6,and 3,and also 2.38 .There are 4 sollutions of equation."

a[] array includes a[]={5.5,4.6,3,2.38,4} Can I gather that numbers to array?and How ?How can I take float numbers from string.

18th Apr 2018, 8:19 AM
Abdusamad
Abdusamad - avatar
11 Respuestas
+ 2
@Abdusamad, Nice to meet you too, I started middle of last year in here, I'm glad if you enjoyed your journey so far : )
19th Apr 2018, 1:04 PM
Ipang
+ 4
Hi @Abdusamad, Have you tried anything so far? I have a code that can extract floating numbers from string, but I would like to see your code first, doesn't matter if it doesn't work yet, I just want to see you try : )
18th Apr 2018, 1:10 PM
Ipang
+ 3
I think No becoz we require similar data type for a particular type of string if you want string of integer then you should go with all strings in it ...if you want float then go with all floats no. only ...there is one more option that is double it can take both integers and floats
18th Apr 2018, 8:32 AM
Yesh Jadav
Yesh Jadav - avatar
+ 3
Hi Abdusamad Remember that an integer belongs to the set of real numbers but a real number may or may not belong to the set of integers. In this case try double a[5]={5.5,4.6,3,2.38,4}
18th Apr 2018, 1:05 PM
Luciano Ariel Caputi
Luciano Ariel Caputi - avatar
+ 3
@Abdusamad, my code works with doubles, I can't mix integers with floating points either because I store the extracted values into a vector to be returned to the function caller, here's my code: https://code.sololearn.com/c50P6Q4F77Mm/?ref=app
18th Apr 2018, 3:28 PM
Ipang
+ 2
#include<iostream> #include<stdlib.h> #include<string.h> using namespace std; int main() { string s=""; char B[100],q[10]; int A[50],p=0; getline(cin,s);//give text which has got numbers strcpy(B,s.c_str());//this function turn to char from string int k=strlen(B); for(int i=0;i<k;i++) { if(isdigit(B[i])) {q[0]=B[i]; A[p]=atoi(q);p++;} } for(int i=0;i<p;i++) cout<<A[i]<<" "; // The problem in this code is that,this code only gather //integers except from float or daouble. //Please send me optimall version of this . }
18th Apr 2018, 2:29 PM
Abdusamad
Abdusamad - avatar
+ 2
@Abdusamad, You have come close, I appreciate your will to try, I will look into your code and come back to you here later, or maybe I can post my code here. P.S. There's no need to mark my answer buddy, remember I haven't helped you with anything just yet : )
18th Apr 2018, 2:38 PM
Ipang
+ 2
@Ipang ,Thank you for your help .I hope we will exchange our codes,I know you are more professional coder than me and can I give next question😀.Where are you from
18th Apr 2018, 4:02 PM
Abdusamad
Abdusamad - avatar
+ 2
OK Ipang ,Nice to meet you , I am from Uzbekistan and I am also student ,I have started learning c++ since January,I found this site a week ago,I think I found my hoped place ,if you have any kind of exercise with c++ ,tell me I could try it and exchange our opinions
19th Apr 2018, 11:38 AM
Abdusamad
Abdusamad - avatar
+ 1
What is your opinion
18th Apr 2018, 2:30 PM
Abdusamad
Abdusamad - avatar
+ 1
@Abdusamad, You're welcome, and sorry for delays, I was on something and didn't see your reply. I am a student here in SoloLearn just like you, not a professional, rather a hobbyist, and yes, I am from Indonesia : )
18th Apr 2018, 6:46 PM
Ipang