+ 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.
11 Respostas
+ 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 : )
+ 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 : )
+ 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
+ 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}
+ 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
+ 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 .
}
+ 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 : )
+ 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
+ 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
+ 1
What is your opinion
+ 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 : )