Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 16th, 2006, 1:21 AM   #1
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
Strange Output

I get this when I try to do this line "Keith2313Hilary"
std::cout << *a_firstPersonsName << '\t\t' << *a_secondPersonsName << std::endl;



#include <iostream>
#include <string>

int main()
{
    std::string firstPersonsName;
    std::string *a_firstPersonsName = new std::string(firstPersonsName);
    std::string secondPersonsName;
    std::string *a_secondPersonsName = new std::string(secondPersonsName);
    double fp_hourly_pay;
    double sp_hourly_pay;
    int fp_wrk_hrs_weekly;
    int sp_wrk_hrs_weekly;
    int fp_hmm;
    int sp_hmm;
    
    std::cout << "Enter first person's name to calculate " << std::endl;
    std::cin >> *a_firstPersonsName;
    std::cout << "How much does " << *a_firstPersonsName << " make an hour? " << std::endl;
    std::cin >> fp_hourly_pay;
    std::cout << "How many hours does " << *a_firstPersonsName << " work in one week? " << std::endl;
    std::cin >> fp_wrk_hrs_weekly;
    std::cout << "How many months do you want see how much " << *a_firstPersonsName << std::endl;
    std::cout << "will have in that many given months? " << std::endl;
    std::cin >> fp_hmm;
    //std::cout << *a_firstPersonsName << " will have a total of $" << (((fp_hourly_pay * fp_wrk_hrs_weekly) * 4) * fp_hmm) << '.' << '\n' << std::endl;
    
    std::cout << "Enter second person's name to calculate " << std::endl;
    std::cin >> *a_secondPersonsName;
    std::cout << "How much does " << *a_secondPersonsName << " make an hour? " << std::endl;
    std::cin >> sp_hourly_pay;
    std::cout << "How many hours does " << *a_secondPersonsName << " work in one week? " << std::endl;
    std::cin >> sp_wrk_hrs_weekly;
    std::cout << "How many months do you want see how much " << *a_secondPersonsName << std::endl;
    std::cout << "will have in that many given months? " << std::endl;
    std::cin >> sp_hmm;
    //std::cout << *a_secondPersonsName << " will have a total of $" << (((sp_hourly_pay * sp_wrk_hrs_weekly) * 4) * sp_hmm) << '.' << '\n' << std::endl;
    
    std::cout << *a_firstPersonsName << '\t\t' << *a_secondPersonsName << std::endl;

    delete a_firstPersonsName;
    delete a_secondPersonsName;
    return 0;
}
KyrinComaBlack is offline   Reply With Quote
Old May 16th, 2006, 1:46 AM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
try putting the \t\t in double quotes. single quotes (') are used for marking single characters, and double quotes (") are for string constants.

Out of curiosity, why do you make a std::string and then use it to make a std::string*? You could just use the std::string and not have to worry about deleting it or dereferencing it, or just use a std::string* with the default constructor and not waste resources on the copy constructor.
Jimbo is offline   Reply With Quote
Old May 16th, 2006, 5:44 AM   #3
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Yeah, if you put "\t\t" you will get

Name1 Name2

And I'd make your number of hours doubles, as it is possible to work for half an hour
Twilight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC