|
Couple more things:
- your minutes_per_hour constant should 60, not 59.
- your hours calculation, even though it is commented out, is not correct.
- after incrementing minutes, you should probably adjust its value using the mod function (% function).
Below is example code also using PJ's setw(2) change:
const int minutes_per_hour = 60;
minutes = minutes + 1;
hours = hours + (minutes / minutes_per_hour);
minutes = minutes % minutes_per_hour;
cout << " The time is: " << hours << ":"<< setfill('0') << setw(2) << minutes << endl;
In Line 1, the expression "x / y" returns the integral portion of x divided by y. When x is 60 and y is 60, this expression yields 1, which will increment the hours by 1. When x is less than y, this expression yields 0, and the hours value is unchanged.
In Line 2, the expression "x % y" returns the remainder value that you get when you divide x by y. If x is less than y, it returns just the value x. If x is 60 and y is 60, the remainder is 0, which handles the case when the minutes goes past 59 (you want it to display 00).
|
|
|
|
|
Thank you so much you people are my heroes
BINARY
|
|
|
|
|
I'll try to inform you of my problem in the best way possible. And I think the best way to do that is to show you a little code that goes with it.
<br />
CObList list;
<br />
---------------------------------------<br />
<br />
class CLineAccess : public CObject
{<br />
DECLARE_DYNAMIC( CLineAccess)<br />
<br />
---------------------------------------<br />
<br />
CLineAccess *temp;<br />
temp = (CLineAccess *)list.GetHead();
pos = list.GetHeadPosition();
<br />
dc.MoveTo(temp->GetStartX(), temp->GetStartY());<br />
dc.LineTo(temp->GetEndX(), temp->GetEndY());<br />
I then have a while loop that gets all the next lines that I am attempting to draw. The only problem is that it seems my CPaintDC dc(this); only draws the last line in the list. Does MoveTo() erase all the previous lines? I get a return of (1) on every run through of the LineTo() so I know that the lines are being drawn. Being that temp is just a local pointer used to traverse through the list I don't see any problems about reusing it. Do any of you have an idea?
|
|
|
|
|
Anonymous wrote: Does MoveTo() erase all the previous lines?
No, but your OnEraseBackground() handler clears all previously drawn lines before calling your OnPaint() handler. You'll need to repaint the entire collection of lines in OnPaint() .
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Anonymous wrote: Does MoveTo() erase all the previous lines?
MoveTo() does not erase anything.
Anonymous wrote: Being that temp is just a local pointer used to traverse through the list I don't see any problems about reusing it.
Reusing temp should not be a problem.
Anonymous wrote: I then have a while loop that gets all the next lines that I am attempting to draw.
Can you show the code for that loop? It almost seems to me that you are drawing the same line over and over again.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote: Can you show the code for that loop? It almost seems to me that you are drawing the same line over and over again.
I'll do even better than that here is everything from my function:
<br />
void LoadAndDrawLines(void)<br />
{<br />
CPaintDC dc(this);<br />
CPen pen;<br />
pen.CreatePen(PS_SOLID, 1, 0x00FF0000);<br />
dc.SelectObject(&pen);<br />
CLineAccess *temp;<br />
int x = 1;<br />
POSITION pos;<br />
<br />
if(list.GetCount() > 0)<br />
{<br />
temp = (CLineAccess *)list.GetHead();<br />
pos = list.GetHeadPosition();<br />
dc.MoveTo(temp->GetStartX(), temp->GetStartY());<br />
dc.LineTo(temp->GetEndX(), temp->GetEndY());<br />
while(x < list.GetCount())<br />
{<br />
temp = (CLineAccess *)list.GetNext(pos);<br />
dc.MoveTo(temp->GetStartX(), temp->GetStartY());<br />
dc.LineTo(temp->GetEndX(), temp->GetEndY());<br />
x++;<br />
}<br />
}<br />
}<br />
LoadAndDrawLines() is called by OnPaint() btw. Also I will clean it up a bit later and move out all the pen stuff and more. Thanks for your help everyone
|
|
|
|
|
The usual pattern to enumerate over all of the elements in an MFC list is as follows:
CObList list;
POSITION position = list.GetHeadPosition();
while (position != NULL) {
element = list.GetNext(position);
} Try CObList[^] in the MSDN.
Software Zen: delete this;
|
|
|
|
|
I met a question when using vc++ .Net 2003,that is, in a project, I declare an array in .h file, but when I initialize that array in .cpp file, the compiler always show me errors. Then how to initialize an array in vc++ .Net 2003?
following is part of the .h and .cpp file.
.h file
#pragma once
#include "stdafx.h"
#include "miscgl.h"
#include "cmath.h"
#include "public.h"
class COpenGLScene
{
public:
COpenGLScene(void);
virtual ~COpenGLScene(void);
......
// backcolor of the scene.
GLclampf backColor[4];
........
};
.CPP FILE
#include <windows.h>
#include <stdio.h>
#include "StdAfx.h"
#include "openglscene.h"
COpenGLScene::COpenGLScene(void)
{
//zRot = 0;
SetCamera();
// First way:
// if using this way, the compiler will give me errors, why and how to using this way?
backColor[] = {0.4f, 0.4f, 0.4f, 1.0f};
// second way:
// if using this way to initialize it, it's OK.
backColor[0] = backColor[1] = backColor[2] = 0.4f;
backColor[3] = 1.0f;
this->isInitialized = FALSE;
}
Can I only initialize the array in the second way?
If I declare a static array, the method to initialize it is easy, but not all the array must be static one at any time.
So, how to initialize the array like the first way?
|
|
|
|
|
Using memcpy() allows you to use the first way.
GLclampf Temp[4] = {0.4f, 0.4f, 0.4f, 0.1f};
memcpy(backColor, Temp, sizeof(Temp) * sizeof(Temp[0]));
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
I wouldn't use memcpy to initialize anything except arrays of integer and character types. Using it with struct 's is problematic, since the struct may have elements that shouldn't be copied directly (like pointers), or it may define an assignment operator.
Software Zen: delete this;
|
|
|
|
|
Thanks,a VC++ newer<it's me=""> has owned the world, internet is everything.
|
|
|
|
|
hello.
i need to get a html code so i can get same values out of it
but what is the best and the fastes way to do it?
|
|
|
|
|
Is there a procedure for copying folders from one place to another?
If there is such a procedure, could you tell me please which is it, and which parameters does it take?
THANK YOU!
|
|
|
|
|
|
All right... I saw it. But I don't understand a thing about that parameter, could you give me an example please?
|
|
|
|
|
|
I had already done that, but i still don't know how to use it... I'm quite new to visual c...
This is how i used it... and the program crashes. I guess i don't know how to handle the parameter...
LPSHFILEOPSTRUCT lpFileOp;
lpFileOp->pFrom="c:\\ad";
lpFileOp->pTo="d:\\";
lpFileOp->fFlags=FOF_ALLOWUNDO;
lpFileOp->wFunc=FO_COPY;
SHFileOperation(lpFileOp);
|
|
|
|
|
|
|
|
|
yesterday i spoke to soon...
i tried to use ravi's and dunn's programs... but they just didn't work, although ai included "c:\\DiskObject.h", or in the other case "c:\\CShellFileOp.h" and it gives the error message "undeclared identifier" when using the related procedures/functions
|
|
|
|
|
I have some experince in vc++.But i lack some fundamentals.If anybody having very good experince want to teach me i can pay for the service.If interested email me back.
Thanks
Ajit
ajitmittal@gmail.com
|
|
|
|
|
|
Hello..
I'm very new to visual C++ , I'm using a console application in Microsoft Visual Studio. NET..
I have a simple application where I want to get some parameters from the user, so i ask the user for it but when i type the answer and press enter on the keyboard the program just crashes (application has encountered a problem..send error to microsoft)
this is my code:
<br />
string host_name; <br />
<br />
printf("ENTER HOST NAME: "); <br />
<br />
<br />
scanf("%s",host_name); <br />
<br />
I have the following include files in stdafx.h file:
#include <iostream>
#include <string.h>
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
I tried declaring host_name as char* but it still crashes.. tries using gets() but doesnt as well..
I also tried doing it the C++ way as follows :
<br />
<br />
using namespace std; <br />
<br />
cout<< "ENTER HOST NAME: "; <br />
cin >>host_name; <br />
And that also crashes the program..
Please tell me where the problem is.. Thank you for ur help..
|
|
|
|