Sponsored Content
Top Forums Programming getting double to be converted Post 302315510 by xiaojesus on Tuesday 12th of May 2009 02:02:58 PM
Old 05-12-2009
getting double to be converted

got a problem.
i have to get A to + 20.70
but i keep getting A + 20 in my logic below.
anyone can guide me on where i go wrong?
i understand it is a double, but i do not noe how to parse it to the function so that it can read in as 20.70 instead of just 20..

i highlighted the problem part in red.. please advices

Code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <string.h>

using namespace std;
class Account
{
      
    //declaration of friend functions
    friend ostream& operator<<(ostream&,const Account&);
    friend istream& operator>>(istream&,Account&);
    friend Account operator +(const Account&,int);
    //friend Account Account::operator+(double r)
    //friend Account operator +(int,const Account&);
    //declaration of public members
    public :
      
        Account();
        Account(int a1,int b1);
        Account operator +(const Account&)const;
  
        
    //declaration of private members    
    private:
            
        int a,b;
};
//constructor for matrix class
Account::Account()
{
    a=0;
    b=0;
                  
}
Account::Account(int a1,int b1)
{
    a=a1;
    b=b1;
           
}
//overloading stream extraction operator
ostream& operator << (ostream &out,const Account &ac)
{
    //out <<  ac.a  << "." << ac.b  << endl;
    out <<  ac.a  << "."<<ac.b  << endl;
    
    
    return out;
    
}//end of function
//overloading stream insertion operator
istream& operator >>(istream &in,Account &ac)
{
    string a,b,s;
    fflush(stdin);
    getline(in,s);
   
 
    a = s.substr(0);
    b = s.substr(0);
    ac.a = atoi(a.c_str());
    
    string::size_type nDecimalPosition = s.find('.');
    if (nDecimalPosition != string::npos)
    ac.b = atoi(s.c_str() + nDecimalPosition + 1);
   
      return in;  
}
 
Account operator +(const Account &rhs,int i)
{
    Account temp;
    //temp.a = rhs.a+i;
    //temp.b = rhs.b+i;
    
    double temprhs = (double)rhs.a + (double)rhs.b / 100;
    double result = 0.0;
    cout << "temprhs " << temprhs << endl;
   
    cout << "i " << i << endl;
    result=temprhs+i;
  
    temp.a = (int)result;
    temp.b = (int)((result - (int)result) * 100);
    
    return temp;
    
    }//end of function 
int main()
{
Account A, B, C;
cout << "Enter first account balance, format xx.yy: ";
cin >> A;
cout << "Enter second account balance, format xx.yy: ";
cin >> B;

C = A + 20.70;
cout << "Addition A + 20.70 = " << C << endl;

system("pause");
return 0;
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print is not in ordered after hash converted to array

Perl: Can anyone tell me why after I convert the hash into an array, when I print it out, it's not in the order like the hash? See below.. my %cityZip = ("Logan, AL", 35098, "Los Angeles, CA", 90001, "OrangeVille, IL", 61060, "Palm Bay, FL",... (6 Replies)
Discussion started by: teiji
6 Replies

2. Shell Programming and Scripting

So I converted columns to rows but I want it to be tab delimited and also I want.....

Hi, So my file looks like this: title number JR 2 JR 2 JR 4 JR 5 NM 5 NM 8 NM 2 NM 8 I used this line that I wrote to convert it to rows so it will look like this: awk -F"\t" '!/^$/{a=a" "$3} END {for ( i in a) {print i,a}}' occ_output.tab > test.txt JR 2 2 4 5 NM 5 8... (4 Replies)
Discussion started by: kylle345
4 Replies

3. Shell Programming and Scripting

can UNIX scripting be converted into binary(executable)

hi i wanna ask that can UNIX scripts be converted into exe files?? if so, how?? and can these scripts be implemented using c++ and using their executable... ---------- Post updated at 02:33 PM ---------- Previous update was at 10:53 AM ---------- plz anybody reply.... and ya i want to... (5 Replies)
Discussion started by: umarbangash
5 Replies

4. Shell Programming and Scripting

printf error (not completely converted)

I'm encountering an issue in printf.. it works on other servers but not this one (SunOS - Kernel Generic_118558-33) root@server # echo $x 2.340 root@server # printf "%.1f" $x printf: 2.340 not completely converted 2,0root@server # anyone has an idea? i was expecting an output of "2.3" (5 Replies)
Discussion started by: ryandegreat25
5 Replies

5. Shell Programming and Scripting

Converted repeated rows into splitted columns

Dear Friends, I have an input file contains lot of datas, which is like repaeated rows report. The output file need to have column wise report, rather than row-wise. Input File random line 1 random line 2 random line 3 ------------------------------------- Start line 1.1 (9.9) ... (1 Reply)
Discussion started by: vasanth.vadalur
1 Replies

6. Red Hat

Spanish Characters get converted in strange chrac

I am trying to sftp a textfile from windows to linux. The file includes some spanish characters. When I vi the file in LINUX, the special (spanish) characters get converted into some strange characters. anyone know how i can resolve this? for example México gets converted into México on LINUX. (0 Replies)
Discussion started by: mrx1350
0 Replies

7. Shell Programming and Scripting

how to keep tab from being converted to space

Hi, I want to read lines from a file, and I'm using two methods 1 use while read line do done<filename 2 use line=`sed -n '3p' filename` however, in both of them, I notice that the tab between fields are automatically converted to space because I want to use awk over the... (10 Replies)
Discussion started by: esolvepolito
10 Replies

8. UNIX for Advanced & Expert Users

Directories converted into files with the same size

Hi Gurus, I know this sounds weird, We have encountered many incidents where some directories on several Solaris 10 boxes, will be converted to files with the same size. for example the file below : -rw-r--r-- 1 rkadm redknee 5027399 Apr 15 00:02 dump This was a directory created... (5 Replies)
Discussion started by: aladdin
5 Replies

9. Shell Programming and Scripting

Curly brackets converted to unicode in script

Is this a bash or wget issue? GNU bash, version 4.4.0(1)-release (x86_64-slackware-linux-gnu) GNU Wget 1.18 built on linux-gnu. If I run wget -O file localhost/{2..4} from the command line, it will download pages 2 to 4 and concatenate them to file - which is what I want. If I put this in a... (4 Replies)
Discussion started by: Ray-V
4 Replies

10. Shell Programming and Scripting

Hebrew converted into jibrish while put command

HI Friends , I have a script which cp xml files from linux to other server thru ftp my xml file contains charcters in hebrew although , the command Binary exists in the script . the files contains Undefined Charcters after converting. script : ftp -p -n $HOST << EOF user $USER $PASSWORD... (9 Replies)
Discussion started by: naamas03
9 Replies
dxaccounts(8)						      System Manager's Manual						     dxaccounts(8)

NAME
dxaccounts - Graphical interface for account administration SYNOPSIS
/usr/bin/X11/dxaccounts DESCRIPTION
The Account Manager application, dxaccounts, helps you manage user accounts on your Tru64 UNIX system. It operates on both base security level systems and enhanced security (C2) level systems. The Account Manager application lets you manage both the local and Network Information Service (NIS) UNIX account databases. NIS is used in order to centrally manage user accounts in a network environment. NIS lets participating systems share a common set of passwd and group files. NIS uses a client-server model. When the Advanced Server for Tru64 UNIX product is installed, the Account Manager application allows you to perform domain user account management for PC users. To start Account Manager from the CDE desktop:Choose the Application Manager from the CDE front panel. Choose the System_Admin group. Choose the DailyAdmin group. Click on the Account Manager icon. Online help is available for the dxaccounts application. To get help, click on any Help button or use the Help pull-down menu. Account Manager replaces the XSysAdmin(8) and XIsso(8) applications. RESTRICTIONS
You must have root privileges to modify system files with this application. If dxaccounts is run without root permission, you may view but not modify account information. In order to make changes to the NIS databases, you must run Account Manager on the machine designated as the NIS server. FILES
Defaults that are shared by the graphical user and command-line interfaces System and account defaults (enhanced security only) Group information for local groups Account information for local user accounts List of shells on the system Group information for NIS groups (on an NIS master) Account information for NIS user accounts (on an NIS master) Protected password authentication database files (enhanced security only) Protected password database (enhanced security only) Protected password database (enhanced security only) Account Manager application Account Manager help volume Account Manager help volume for enhanced security Directory containing Account Manager application icons Application defaults file that sets the default values for the X resources Account Manager message catalog Default directory for user account initial files SEE ALSO
Commands: auditmask(8), authck(8), groupadd(8), groupdel(8), groupmod(8), login(1), nis_intro(7), passwd(1), secsetup(8), useradd(8), userdel(8), usermod(8), XIsso(8), XSysAdmin(8) Functions: acceptable_password(3), getprpwent(3), getpwent(3) Files: authcap(4), default(4), group(4), passwd(4) Manuals: System Administration, Advanced Server for UNIX Installation and Administration, Advanced Server for UNIX Concepts and Plan- ning</docbook> dxaccounts(8)
All times are GMT -4. The time now is 09:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy