| | |
please help with code emmidiately
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 1
hi I have crreated a conde to try and take input rom a user as a string then break it up into bits and pass it o it's
functions but the values are not releacting at the functions and anyone has any other way o converting a string into a float could they please tell me how it's done. The atof() function seems to be changing the values in the array and stoing zero instead o the original values.
here is the code.
functions but the values are not releacting at the functions and anyone has any other way o converting a string into a float could they please tell me how it's done. The atof() function seems to be changing the values in the array and stoing zero instead o the original values.
here is the code.
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<string> #include<stdlib.h> #include<stdio.h> using namespace std; void setID(int i); void setRate(float r); void setPrice(float p); //using namespace std; int main() { string all,msg; cin>>all; //1234,566666,0.9 int p=0,q=0; for(int n=0;n<(all.length());n++) { if( p==0 && all[n]==',') { msg=all.substr(0,(n+1)); setID(atoi(msg.c_str())); q=n; p++; } if(p==1 && all[n]==',') { msg=all.substr(q,(n+1)); cout<<"ha"<<msg<<endl<<atof(msg.c_str())<<endl; setPrice(atof(msg.c_str())); p++; q=n; } if(p==2 && all[n]==',') { msg=all.substr(q,(n+1)); cout<<"he"<<msg<<endl<<atof(msg.c_str())<<endl; setPrice(atof(msg.c_str())); p++; } } } void setID(int i) {float ID=i; cout<<i<<endl;} void setRate(float r) { float Rate=r; cout<<Rate<<endl; } void setPrice(float p) {float Price=p; cout<<Price<<endl; }
Last edited by Ancient Dragon; Nov 6th, 2008 at 8:42 am. Reason: add code tags
![]() |
Other Threads in the C++ Forum
- Previous Thread: #include "form.h" problem
- Next Thread: Factors of a Polynomial
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






