Newbie Coder, Sub Help

This is a discussion on Newbie Coder, Sub Help within the C++ Programming forums, part of the General Programming Boards category; i have been a c++ programmer for just under a month now (i think) and have programmed in a number ...

  1. #1
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80

    Question Sub, Probs

    i have been a c++ programmer for just under a month now (i think) and have programmed in a number of previous languages, for the last day ive been trying to port one of my programs from vb to c++, and apart from the syntax being so precise (compared to vb) i have had no probs well except i guess 2 ^_^, first off i want a user to be able to input a float as a string then convert it to a long or float, iv got this to work fine but using my process u have to rely on a base specific type (so i decided on a double) but due to this i can retrieve longs, shorts and doubles but cant get real/floats (i have posted my code below (the project itself is a high level tag based language (almost converted all the core of a language to it)) the second prob is this, once my tag if statement has been evaluated if true i want to process the script, but to do so i have to revisit the same sub but this will change the int that holds the script pos, now if i use a secondary it to hold the current one then process then return its fine but doesnt then allow if>if> (multilevel processing) now i know i could make the int an array and have a process to re establish the position but this still limits me to the max array size of int) my code is below any help would be great (btw dont make fun of the way i craply coded it as i have only been coding in c++ for under a month :P )

    >>>>>Moved to attatchment file on next post *.cpp
    Last edited by MicroFiend; 12-04-2002 at 02:11 PM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    for those evaluating your script it helps if you can narrow down the scope of material they need to look over--sort a like asking you to proofread a given page rather than a whole book to find the error I know is there.

    Second, most of us are used to indentation when looking at code. Unfortunately, you need to do a little trick to get the indentation to show up when posting code to the board---but you should always do it---place the word code in square brackets preceding the code and the phrase /code in square brackets after the code.

    You should be able to the the atox() family to convert from string to numerical values. It's atoi() to convert to type int, atol() to convert to type long, and atof() to convert to double or float. If you want to use fractions or imaginary numbers you need to divise your own classes.

    Often you can review values in variables without changing the value stored in them, but I'd have to see the code/algorithm in question before going further.

  3. #3
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    heres the code (on attachment)
    Attached Files Attached Files

  4. #4
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    elad said>>

    You should be able to the the atox() family to convert from string to numerical values. It's atoi() to convert to type int, atol() to convert to type long, and atof() to convert to double or float. If you want to use fractions or imaginary numbers you need to divise your own classes.

    lol shows how much i know about the c++ language i made my own sub (below) to do this :P and all i really had to do was at**()
    lol, thanx, btw iv used the array sub idea for the multi level procs;

    Code:
    double StringToValue(char T1[])
    {
    	char NumberBuffer[12] = "0123456789.";
    	int pval=0;
    	int cval=0;
    	int xval=0;
    	double magval=1;
    	double endval=0;
    	int tlen=StringLength(T1);
    	int cc=1; // 1 or else it will loop 1 more than expected if 0
    	int repmag=tlen;
    	int pp=0;
    
    	while (pp<tlen)
    	{
    		if(T1[pp] == NumberBuffer[10])
    		{
    			repmag=pp; //find the true length of <= whole numbers so it will correctly divide into floats
    					   //the . and array 0 cancel each other out
    			break;
    		}
    		++pp;
    	}
    		
    	
    	while (cc<repmag) 
    	{
    		magval*=10;
    		++cc;
    	}
    
    while(pval<tlen)  // < than or else it will loop 1 more than expected if <= to
    {
    	while(cval<=9)
    	{
    		if (((int)T1[pval]) == ((int)NumberBuffer[cval]))	
    		{
    			endval+=(cval*magval); //yay the value ^_^
    			cval=0;
    			break;
    		}
    
    		if (((int)T1[pval]) == ((int)NumberBuffer[10]))	
    		{
    			 //return the .
    			cval=0;
    			break;
    		}
    
    		++cval;
    	}
    	magval/=10;
    	++pval;
    }	
    	return endval;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 02:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 08:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 03:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21