Advertisements
Offline
WehLee
Posts: 2
Joined: Wed Jan 30, 2013 9:24 am
Hi,

Bare with me as I am very new to C++ and have a query to asl for assistance to ask. Still new and learning through this sites tutorial.

I came across this and would like to give it a try. Below, is the result with corresponding formats.

Date, X-Code, Activity, Shares, Price
29/01/2012, XYZ, buy, 100, 20.00
30/01/2012, XYZ, buy, 20, 24.00
31/01/2012, XYZ, buy, 200, 36.00
05/02/2012, XYZ, sell, 150, 30.00
17/02/2012, XYZ, sell, 40, 35.50
02/03/2012, XYZ, buy, 100, 27.25

I have seen some example of getting the date. But, no idea how to do it as above.

Could anyone give me some heads-up on what to do.

Appreciate your assistance...


Thank you,


Marcus

Postby WehLee » Fri Feb 01, 2013 8:14 am

Offline
WehLee
Posts: 2
Joined: Wed Jan 30, 2013 9:24 am
Here is what I have done so far.

Code: Select all
#include <ctime>
#include <iostream>
using namespace std;

void TodaysDate()
{
        time_t now = time(0);
        tm *ltm = localtime(&now);

        cout << ltm->tm_mday << '/' << 01 + ltm->tm_mon << '/' << 1900 + ltm->tm_year << endl;
}

// Declaration of main()   
int main()
{
    // variables declaration
    int Day1, Day2, Day3, Day4, e;
    float f;
    float g;
    float h;
    float i;
    float j;
    float k;

    //actual initialization
    Day1 = 100;                   
    Day2 = 20;             
    Day3 = 200;           
    Day4 = 150;           
    e = 40;             
    f = 20.00;
    g = 24.00;
    h = 36.00;
    i = 30.00;
    j = 35.50;
    k = 27.55;

    cout << TodaysDate << ',' << "ABC" << ',' << "buy" << ',' << Day1 << ',' << f <<endl;
    return 0;
}


I got a result "1,ABC,buy,100,20". But, what I want is "currentdate,ABC,buy,100,20.00".

How to do this.


Thanks


Wehlee