C++ , i need small help

Discussion in 'Programming' started by lebcrew, Sep 13, 2009.

  1. #1
    alright,here's a simple program i've made for a game i used to play,it's to calculate a selloff-value for the weapons...

    #include<iostream>
    using namespace std;
    int main()
    {
        unsigned long long x,y,z,c,_cbpm,_cis,_cnun,_clt;
        unsigned long long _bpm=637500,_is=562500,_nun=435000,_lt=300000;
        char t;
        cout<<"Remember this program is made,only to calculate selloff value for BPM,IS,NUN,LT..."<<endl<<endl;
        cout<<"Enter how many BPM: ";
        cin>>x;
        cout<<endl;
        cout<<"Enter how many IS: ";
        cin>>y;
        cout<<endl;
        cout<<"Enter how many NUN: ";
        cin>>z;
        cout<<endl;
        cout<<"Enter how many LT: ";
        cin>>c;
        cout<<endl;
        _cbpm=_bpm*x;
        _cis=_is*y;
        _cnun=_nun*z;
        _clt=_lt*c;
        cout<<"Your selloff value is: "<<(_cbpm)+(_cis)+(_cnun)+(_clt)<<endl;
        cout<<"Enter any key to exit";
        cin>>t;
        return 0;
    }
        
    
    Code (markup):
    but the prob i'm facing is that let's say the output was like 12bil it shows up @ the end: 12546787

    i want the digits to be seperated like each 3 digits seperated by a ,

    i tried lookin' for this prob online and what i got was a Function for this as the following:

    #include<iostream>
    #include<sstream>
    
    using namespace std;
    
    void rangers_integer_print (int n)
    {
         stringstream s;
         char c;
         
         s << n;
         
         while (s.get(c))
         cout<< c <<" ";
         }
         
         int main()
         {
              int n,c;
              
              cout<<endl<<"Enter number: ";
              cin>>n;
              
              rangers_integer_print(n);
              cin>>c;
              }
    
    Code (markup):
    but when modified it and added it into my program the output was: 1 2 5 6 4 3 2 3 3....

    each digit seperated by a SPACE ...not what i'm lookin' for
     
    lebcrew, Sep 13, 2009 IP
  2. myselfandI

    myselfandI Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    so where are u guys...

    no one good enough in c++ ? :eek:
     
    myselfandI, Sep 13, 2009 IP
  3. sp360

    sp360 Well-Known Member

    Messages:
    1,023
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    160
    #3
    sp360, Sep 13, 2009 IP
  4. myselfandI

    myselfandI Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    any others ???
    :eek:
    where is the participation guys come on!!!!
    waiting u
     
    myselfandI, Sep 13, 2009 IP
  5. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    I am stopping here, you can continue on. If you have no experience in C++, I would advising hiring a coder:

    
    // Reverse string function
    int ReverseString(char *str)
    {
         int x = strlen(str); //takes length of string
         for(int y = x; y >= (x/2)+1; y--) //for loop arranging the string
         {
              swap(str[x-y],str[y-1]); // swaps letters
         }
         return 0; //return
    }
    
    void rangers_integer_print (int n)
    {
    	string mystring;
    	int strSize;
    	int counter=3;
    	int newCount=0;
    
    
    	stringstream out;
    	out << n;
    	mystring = out.str();
    	strSize =  mystring.size();
    	strSize--;
    	cout << strSize;
    	char *newString = new char[strSize+10];
    
    	for(int x=strSize;x>=0;x--)
    	{
    		newString[newCount++] = mystring[x];
    		counter--;
    		if(counter == 0)
    		{
    			newString[newCount++] = ',';
    			counter = 3;
    		}
    		
    	}
    	delete [] newString;
    
    	cout << ReverseString(newString);
    }
    
    Code (markup):
    Code is almost complete.
     
    ThePHPMaster, Sep 13, 2009 IP