|
I hope someone has seen this tutorial ?
This is from the quiz at the end of the first chapter.
question 13)
The moon’s gravity is about 17 percent that of Earth’s. Write a program that displays a table that shows Earth pounds and their equivalent moon weight. Have the table run from 1 to 100 pounds. Output a newline every 25 pounds.
I think I'm close , here's what I have so far.
// This project the For Loop, the If statement, and code blocks
//to display a program that converts Metrics into Feet
#include <iostream>
using namespace std;
int main()
{
int temp;
double e; // holds the wieght on earth
double m; // holds the conversion to moon wieght
int counter;
int d;
counter = 0; // counter is initially set at 0
for(d= 1.0; e <= 100; e++) {
m = e / 17.; // convert to meters
cout << e << "earth is" << m << " moon.\n";
cin >> temp;
counter++; //encrement the counter with each loop iteration
// every tenth line, print a blank line
if ( counter == 100 ) {
cout << " \n "; // output a blank line
counter = 0; // reset the counter
}
}
cin >> temp;
return 0;
}
painterdave
aka. FlashDave
painterdave22@wildblue.net
|
|
|
|
|
painterdave wrote: for(d= 1.0; e <= 100; e++)
Probably this should be
for(e= 1.0; e <= 100; e++)
painterdave wrote: // every tenth line, print a blank line
if ( counter == 100 ) {
cout << " \n "; // output a blank line
}
Shouldn't that be:
if (counter==25)
{
cout << endl;
counter=0;
}
else
{
counter++
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am just starting on this journey, so
any help is apreciated, it's always good to get another point of view.
What makes it even more difficult is when the text that you are using , is a little bit off, or out of date or somehtings missing. I mean when you do it the way they tell you to do it , and it doesn't work ?, I thought it was me , but a friend of mine who is a programmer, had to give it a couple of fixes.
painterdave
|
|
|
|
|
painterdave wrote: I mean when you do it the way they tell you to do it , and it doesn't work ?, I thought it was me
Well, I can feel your pain. Anyway, don't worry, sooner you will laugh at your starting difficulty.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
painterdave wrote: for(d= 1.0; e <= 100; e++) {
I would always use integral values for loop counters thus:
for (counter = 1; counter <= 100; ++counter)
{
d = (double)counter;
m = d * 0.17;
cout << e << "earth is" << m << " moon.\n";
if (0 == counter % 25)
cout << endl;
}
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
painterdave wrote: for(d= 1.0; e <= 100; e++) {
e is never initialized. You should also consider making it an int . I would not worry about anything else until you have a loop that can count from 1 to 100 .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
painterdave wrote: The moon’s gravity is about 17 percent that of Earth’s.
painterdave wrote: m = e / 17.; // convert to meters
Might help if you understood what percent means. Also, what does meters have to do with the problem what dealing in weight?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
This class is used to save the pix paths in the ListBox into a file. CListItemData is a class that stores
additional info for every item in ListBox. This class operates correctly.
void CCfgFile::Serialize( const CListItemData& lid, const CListBox& lst )
{
loadConfigFile();
fPic.Seek( sizeof( CONFIGFILE_HEADER ), CFile::begin );
CString str;
int i = 0;
while( i < lst.GetCount() )
{
lst.GetText( i, str );
str = lid.GetDir(i) + _T("\\") + str + _T(".") + lid.GetType(i);
memset( rcd.strPath, 0, sizeof( rcd.strPath ) );
memset( rcd.nStyle, 0, sizeof( rcd.nStyle ) );
strcpy( rcd.strPath, str );
itoa( lid.GetStyle(i), rcd.nStyle, 10 );
rcd.nStyle[1] = '\0';
fPic.Write( &rcd, sizeof( CONFIGFILE_RECORD ) );
i++;
}
fPic.Close();
}
The prob occurs. Sometimes the file buffer is updated and the ListBox can show the updated data. But after I exit the proram, the disk file is not updated. This really confuses me. Even if I use CFile::Flush(), it's the same. Anyone could help me out? Really thanx.
|
|
|
|
|
I think there is not enough information about your problem in your post, so can you just provide some more information? Like definition of the struct type of "rcd"?
Besides, maybe you can try to debug the application to find the reason of your problem
|
|
|
|
|
What is fPic? That's a pretty crucial bit of missing data...
How is the file opened?
Could it be failing on the opening (ie, already open elsewhere) and you're not handling the errors from a failed opening?
Iain.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
struct CONFIGFILE_RECORD
{
char strPath[MAX_PATH];
char nStyle[2];
};
struct CONFIGFILE_HEADER
{
char bHasPic[2];
char bOrder[2];
char nTime[5];
char bEffect[2];
char nNum[3];
char nPos[3];
};
BOOL CCfgFile::loadConfigFile()
{
BOOL ret = FALSE;
char dir[MAX_PATH];
::GetCurrentDirectory( MAX_PATH, dir );
strcat( dir, "\\config" );
UINT mode = CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite | CFile::shareDenyNone;
if( fPic.m_hFile )
fPic.Close();
ret = fPic.Open( dir, mode );
if( !fPic.GetLength() )
{
strcpy( hd.bHasPic, _T("0") );
strcpy( hd.bOrder, _T("1") );
strcpy( hd.nTime, _T("9999") );
strcpy( hd.bEffect, _T("0") );
strcpy( hd.nNum, _T("0") );
strcpy( hd.nPos, _T("0") );
fPic.Write( &hd, sizeof( CONFIGFILE_HEADER ) );
}
return ret;
}
|
|
|
|
|
You're first writing a CONFIGFILE_HEADER record to the file, rewinding it, and then writing one or more CONFIGFILE_RECORD records to it. Is that the intent?
Krauze wrote: // get the current dir
char dir[MAX_PATH];
::GetCurrentDirectory( MAX_PATH, dir );
strcat( dir, "\\config" );
This will not always result in the same path.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Your ret is set to false and the return value from the file open is returned but never used in your main function.
|
|
|
|
|
Thank y'all! I've got it solved with the help of DavidCrow. Actually, ::GetCurrentDirectory() may return inconsistent paths.
|
|
|
|
|
I am making a desktop development.But there is a problem that I can't solve till now.In the development I have to add some command buttons to the listbox.And the first item is different from others.It is like a header with text.So how can I do it.Thanks.
|
|
|
|
|
Just try with the subclassing, You have subclass a control to get the rid, try this example Control Subclassing[^]
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks your help.Now I have solved the problem.
|
|
|
|
|
Hi all--
I've got a program where you click and add points to make a polygon using a linked list, and now I want it where by pressing a button it will take the points on the polygon and make it a cubic b spline curve. However I have no experience with the b spline curves and am having trouble with were to start. So I was wondering if you would be able to help me with the pseudo code for this, using C so that I can better understand what I'm trying to do. Here is what I have come up with so far (which isn't much unfortunately):
Create a drawCurve function that traverses the linked list in order.
Take the first four points to draw the spline curve, then the next one over each time.
[insert how to do the math here (of which I am confused about)]
Use a state machine to implement. So pressing a button of my choice will change between the drawing polygon state and the draw curve state.
Thank you very much for your help.
|
|
|
|
|
Now, where's that 'homework' tag?
L u n a t i c F r i n g e
|
|
|
|
|
I'm not asking you to do it for me, I'm just trying to figure out where to start
|
|
|
|
|
Carl De Boor's book "A practical guide to splines" has pseudo code for what you want.
|
|
|
|
|
|
Buddys,
How to create database and manipulations on that databse by using sqlite databse. plz provide me solution.
iam trying to create with add CppSQLite3.h in my code, but its not working, getting some sqlite exception.
|
|
|
|
|
kirancgi wrote: plz provide me solution.
This is not possible in a forum; try reading some of the articles on databases.
kirancgi wrote: its not working, getting some sqlite exception.
We cannot guess what this could mean. Show your code where the exception occurs, and include the exact wording of the exception. Only then can anyone try and help to diagnose the problem.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard MacCutchan wrote: Only then can anyone try and help to diagnose the problem.
Well, you're not much of a mindreader now are you?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|