|
Thanks for your reply, Roman.
By adding LVSIL_SMALL
(ctlList.SetImageList(&m_ctlImage1,LVSIL_SMALL);)
I got the listview to display the first loaded icon. (In the imagelist there are two different icons.) But the strange thing is that I have to put -1 in the actual line where I add the listitem, as follows:
ctlList.AddItem(nItem,NULL,CCrack::strVARIANT(var),-1);
If I put anything else, the icon disappears!!
As I have two icons in the imagelist, I should have thought I should put 0 or 1 in, and I should be able to vary which icon appears. (The -1 entry is the default.)
I would be most grateful for help as to why this is happening.
Thanks,
trimtrom
|
|
|
|
|
I'm trying....to write a program to compute phone bill with discounts and taxes....I got stumped though... I can't have the time with a 60 in it....How do I go about putting this in my code...and I need to compute to Taxes....I need to compute for before the taxes are added in with discounts where needed and with the tax after wards....any help would be grateful....
thanks
Julie
// Purpose: Write a program that computes a phone bill for long distance. Program will ask user to input the number of calls to process.
// Then for each call the user will input the start time for a call based on a 24-hour military time clock and
// length of the call in minutes. The program then will compute and print the cost fo the call, before and after
// the tax has been added. Tax will be computed after discounts (where needed).
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
const float REGULAR_RATE = 0.20f;
const float AFTER_BEFORE = 0.25f;
const float LONGER_SIXTY = .15f;
void DisplayOpeningScreen();
void PrintBlankLines(int);
void PrintTotalBeforeTax(float, int);
void PrintTotalAfterTax(float, int);
int main()
{
int numofCalls;
int callCount;
int startTime;
int lengthinMin;
float sumofCalls;
float callcost;
float discrate1;
float discrate2;
float doubleDisc;
DisplayOpeningScreen();
cout << "How many phone calls will be processed? ";
cin >> numofCalls;
PrintBlankLines(2);
callCount = 0;
sumofCalls = 0;
while (callCount < numofCalls)
{
cout << "The start time of the call in military time is: ";
cin >> startTime;
cout << endl;
while (startTime > 2359 || startTime <0 )
{
cout << "Error.....please enter a vaild start time: \n";
cin >> startTime;
}
cout << "The length of the call in minutes is: ";
cin >> lengthinMin;
cout <<endl;
="" while="" (lengthinmin="" <="" 1)
="" {
="" cout="" <<="" "error....please="" enter="" a="" vaild="" length="" time:="" \n";
="" cin="">> lengthinMin;
}
callcost = lengthinMin * REGULAR_RATE;
if (startTime >= 1800 || startTime < 800)
{
cout << "The call receives a 25% discount\n";
discrate1 = (lengthinMin * AFTER_BEFORE) - float(callcost) ;
cout << "The call with the discount is: " << discrate1 << endl;
}
if (lengthinMin >= 60)
{
cout << "The call receives a 15% discount\n";
discrate2 = float(callcost) - (lengthinMin * LONGER_SIXTY);
cout << "The call with the discount is: " << discrate2 << endl;
}
if (startTime >= 1800 || startTime < 800 && lengthinMin >+60)
{
doubleDisc = discrate1 + discrate2;
cout << "This call receives both a 15% discount and a 25% discount.\n";
cout << "The call with both discounts is: " << doubleDisc << endl;
}
callCount++;
}
PrintTotalBeforeTax(callcost, numofCalls);
return 0;
}
//****************************************************************************************************************************************
void DisplayOpeningScreen()
// Purpose: Explains the program to the user
// Pre: None
{
cout << "/n \"Long Distance Phone Bills\"\n";
PrintBlankLines(3);
cout << "This Program will start by asking you the user to enter the number of calls to be processed. Then you will be asked " << endl;
cout << "to enter the start time for each call based on a 24-hour (military time) clock and the length of the call in minutes.\n\n";
cout << "The program will then compute and print the cost of the call, before and after the federal tax has been addded. Any and all\n";
cout << "discounts will be computed before the federal tax.\n\n";
cout << "The Rate Structure for long distance calls is as follows:\n\n";
cout << " * The regular rate for a call is $" << REGULAR_RATE << " per minute " << endl;
cout << " * Any call started at or after 6:00p.m. (1800 hours) but before 8:00a.m. (800 hous)\n";
cout << " receives a 25% discount" << endl;
cout << " * Any call longer than 60 minutes receives a 15% discount on its cost (after the start\n";
cout << " time discount is subtracted, if appropriate)" << endl;
cout << " * All calls are subject to 4% federal tax, which is computed after the discounts\n\n";
PrintBlankLines(4);
system("pause");
system("cls");
}
//******************************************************************************************************************************************
void PrintBlankLines(/*in*/ int numLines)
// Purpose: Print numLines blank lines on the output screen
// Pre: numlines > 0
{
int lineCt;
lineCt = 1;
while (lineCt <= numLines)
{
cout << endl;
lineCt++;
}
}
//******************************************************************************************************************************************
void PrintTotalBeforeTax(/*in*/ float callcost, /*in*/ int numofCalls)
// Purpose: Prints the total cost of all of the calls inputed by user with out federal tax added on.
// Pre: callcost >= 0.00, num >= 0
{
system("pause");
system("cls");
PrintBlankLines(8);
cout << " Final Totals Before Tax\n\n";
cout << " Number of Calls Processed: " << numofCalls << endl;
cout << " Total amount of calls before tax: " << callcost << endl;
PrintBlankLines(9);
}
//********************************************************************************************************************************************
|
|
|
|
|
Autumn wrote:
#include
#include
#include
using namespace std;
You need to use the formatting buttons above the emoticons below to add < and >, or check "Display message as is' above your signature below. I presume you added stdafx, iostream and what else ?
Also, using namespace std makes namespaces redundant. You should instead have
using std::cout;
using std::cin;
using std::endl;
etc.
The way I format the above code block is to wrap it in a <pre> tag.
Autumn wrote:
while (callCount < numofCalls)
Because you already know the desired range before you start, this would be better as a for loop.
Also, I think your cin calls are failing, probably because you don't call cin.flush(). I entered one number and got full output of everything.
Autumn wrote:
void PrintBlankLines(/*in*/ int numLines)
// Purpose: Print numLines blank lines on the output screen
// Pre: numlines > 0
{
int lineCt;
lineCt = 1;
while (lineCt <= numLines)
{
cout << endl;
lineCt++;
}
}
Again, this would be better as a for loop. You should also always set your variables a value when you create them, although in this case you do that in the second line, the two should be combined.
Also, endl does a flush as well as a new line. This is expensive, and should be avoided. cout << "\r\n" instead to avoid this extra penalty, and if ( as I suspect ) you're doing this for a class, comment the reason you've done so.
I presume your main problem is that you're having trouble calculating times because they cannot be greater than 59 for minutes ? I can't see where in the code you want to do this, but why can't you just do a while loop subtracting 60 from the minutes while they are > 60, and adding 1 to the hours every time ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
You are correct this is for a class....sometimes I just think to hard and get a block. I uderstand with the 60 but what i need is a error loop so if the user prints a 60 then an wrror message appears.... but if I do <60 then it won't let me process any number higher than 60? Any ideas for a code....Thank Christian!!
Autumn
|
|
|
|
|
Autunmsky wrote:
sometimes I just think to hard and get a block.
*grin* I know what you mean.
Autunmsky wrote:
I uderstand with the 60 but what i need is a error loop so if the user prints a 60 then an wrror message appears.... but if I do <60 then it won't let me process any number higher than 60?
Well, say that the numer of hours is stored as m_hours, and the number of minutes as m_minutes, then you could do this:
if (m_minutes > 59)
{
cout << "Value entered greater than 59 minutes, converting to hours"
while(m_minutes > 59)
{
++m_hours;
m_minutes -= 60;
cout << ".";
}
cout << std::endl;
}
Ideally, you would probably ask the user if they want to re-enter the value, I'd think it's more likely to be an error. The easiest way to do this would be as follows:
int m_minutes = 0;
cout << "Please enter the number of minutes (0-59)";
do
{
cin >> m_minutes;
if (m_minutes < 0 || m_minutes > 59) cout "Invalid number entered, please try again ";
cin.flush();
} while (m_minutes < 0 || m_minutes > 59);
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Thanks once a again Christian.....you make it looks so easy!! Now how would I get my program to calcute the totals with and without tax.....would I just use my total sums of calls and then add tax....but how would get the discounts to calc. the price of the call and add it to my total? Or Am I just losing my mind??
Autumn
|
|
|
|
|
Autunmsky wrote:
would I just use my total sums of calls and then add tax
Yes, I'd declare a variable for the total, the another for the total with tax, and simply set that to be the total, then add tax.
Autunmsky wrote:
but how would get the discounts to calc. the price of the call and add it to my total?
I'm not sure what you're tryng to do ? Could you break it down into a step by step process of what needs to be calculated and displayed, so I see what it is you want to end up with ?
Autunmsky wrote:
Or Am I just losing my mind??
I'm afraid I'm not qualified to comment there. :P
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
ok here we go.....what i need to do it.....apply the discounts where needed which is already in the program. What i need it to do is give me the cost of the call with the discount...or discounts. Then at the end...final screen I need to show the cost of all of the calls before tax and the cost of the calls after tax.....but all discounts have to be applied before the cost of all of the calls beofre and after tax...does this help??
Autumn
|
|
|
|
|
So you need to keep the cost of the calls with discounts applied in one variable, and the discounts themselves in another variable, and then if you ever need to know the cost of the calls before discounts ( which seems not to happen too often, hence my suggestion that you do it this way ), then you can just add the discounts to the call costs.
Does that do it ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
i think that makes sense...now i just have to code it ....with the 60 thing again....I have to do it in Military time....so if the user types 1860 I need it to send at error message....would I still do that the same way you suggested to do it before?
Autumn
|
|
|
|
|
Your system overall is very fragile, I personally would have strings entered and then look for spaces or : or ., before chopping up the numbers. But it will work like this, just make sure the number is no more than 4 digits long, then to get the minutes you would say
minutes = total & 99;
and
hours = total - minutes;
I believe that's right, anyhow.
Once you have minutes and seconds, I would be more inclined to have the UI report an invalid number and ask again, because it's unlikely someone would deliberately enter 1375 for 2:15 pm, but if you prefer to roll the values around, yes that is how I would do it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
ok now I am wasy confused!!! I need to go to the mental block ward!! So would I use a while statement...my only problem is is that i don't know how to use it in an error statement message....while (startTime>=60) ....but that would give me every number above 60 as an error..... I still don't get it....I'm so sorry to be such a pain!!!
Autumn
|
|
|
|
|
ONLY the 60...only the 60 and above for minutes.!!!I'm going crazy!!!!
Autumn
|
|
|
|
|
I'd use a do-while, then have it run while the number of minutes > 59. Thus it will keep asking until a valid time is entered.
Autunmsky wrote:
an error statement message
What do you mean by this ? You want to use cerr ?
Autunmsky wrote:
but that would give me every number above 60 as an error.....
No, strip it into minutes and hours first, then check the minutes. The bit I entered to do that may be confusing, but basically an & ( a bitwise and ) only stores values common to both. Therefore it will only return the portion of the number that is < 100, which is the minutes.
So 1102 & 99 = 2, 34534535023 & 99 = 23, etc.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
ok this is what the sheet says.....
use an additional error checking loop to validate the start time. The start time is valid if it is in the range between 0 and 2359, inclusive, and if the last 2 digits of the start time are not greater than 59. Print an error message and continue to ask the user for a valid start time until the user enters a valid one....
Autumn
|
|
|
|
|
Well, that's exactly what I've been advocating. The steps are
create the variables and initialise to 0.
start a do...while loop, and ask for the value.
use the bitwise and to strip the value into hours and minutes.
check if the minutes > 59, if so, print an error message
close do..while loop, the while condition is if our minutes > 59 or < 0. Remember this is a scope outside our loop, that's why we created the variables used first.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hey, I am having a problem with CreateBitmap. I found in some code where this function gets called. It is inside a DLL written in C. It uses a video file created from the waveform of a .wav file. When I have a wav file that is over 42 minutes long (which means it is a BIG file), this function seems to fail for some reason. I call this function with a Width, Height, 1, 1, and basically a pointer to -1 (I know this might seem weird but this is how it has always been). I did GetLastError and returned an 87, meaning "The parameter is incorrect". The parameters never really change except for the width, on .wav files that are over 42 minutes long the width is 33000 and higher. I thought an integer could hold this value, am I wrong? Could it be something else????
|
|
|
|
|
I suspect that you've answered your own question - I reckon that the bitmap being created is simply too big. However, your last parameter should most definately be 0 (NULL), and not -1.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Okay, if the bitmap is too big, any idea why it would be giving me the incorrect parameter as the last message? I did do a little more testing and it seems to all depend on the width. Sometimes, it will pass in 21000 and it will create the handle. Other times, 21000 will be passed in and it will fail. Why would it fail, any thoughts????
|
|
|
|
|
Windows will not allow you to create bitmaps over a certain size, therefore if you go over that size limit, 'incorrect parameter' is a correct, if not very helpful, thing to return. I remember this came up when I was writing a paint program. It's possible that the bigger the bitmap, the less *likely* it is to be able to allocate that block of memory. I don't know the details, I only know there *is* a limit.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Okay, thank you very much for all the information.
|
|
|
|
|
Hi,
I am using Direct Animation in my MFC MDI project, I create it like this
CWnd m_ctl.CreateControl( "DirectAnimation.DirectAnimationIntegratedMediaControl.1", "DAWindowedControl", WS_VISIBLE, rc, this, 101);
but when I use it to display animation, it seems it dose not update the screen, it is updated when resize the child window. Do you know how to solve it?
You can download the program at http://billhao.diy.163.com/main.exe, then click the icon A in toolbar to see the result.
Thanks
bill
|
|
|
|
|
At a guess, you need to add the WS_CHILD style and possibly some others as well to get your window working correctly.
Roger Allen
Sonork 100.10016
In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
|
|
|
|
|
I have added WS_CHILD and some other style, but it still dosen't work. Any idea?
bill
|
|
|
|
|
pls help me!
Thanks.
bill
|
|
|
|
|