> MFC vs WIN forms - Which road to take?
Neither...
Then? Java? ;)
> MFC vs WIN forms - Which road to take?
Neither...
Then? Java? ;)
OKay. Tell me whether the output of this function is okay. If not tell me why.
bool validateRange(int theSquare [][4], const int numRows, const int magicvalue)
{
bool good = true;
int i, j, num[16] = {0};
cout << "RANG: ";
for (i = 0; i<4 ; i++)
{
for (j=0;j<4;j++)
{
if (theSquare[i][j]<1 || theSquare[i][j] >16)
{
good = false;
cout <<theSquare[i][j] << " ";
}
else
{
num[theSquare[i][j] - 1 ] +=1; // The elements at num begins at 0; so we have to use the - 1
if (num[theSquare[i][j] - 1 ] > 1)
{
cout <<theSquare[i][j] << " ";
good = false;
}
}
}
}
if (good == true)
{
cout <<"VALID" << endl;
}
else
{
cout << endl;
}
return good;
}
the code you gave me outputs
{1,1,1,2,2,2, 18}
I dont think so. It should output {1,1,1,2,2,2}. My code does not output 18. That is your part.
when it should output
{1,1,1,2,2,2,17,18,18,-1}
As I said before the out of range checking is your part. By making a small change in the above code you should be able to make it work the way you want.
Another thing, when you post code, format it properly. The braces should be vertically placed and no code other than comments should be in the lines with braces. It is difficult to read the code in the way you write them.
Okay, no need to go through my rigmarole.
int occurences[ 16 ] = { 0 } ;
for ( int i = 0 ; i < 4 ; i++ )
{
for ( int j = 0 ; j < 4 ; j++ )
{
// Range Check here
if RangeOK
{
occurences[ array[ i ][ j ] ] += 1;
if ( occurences [ array[ i ][ j ] ] > 1 )
cout << "Duplicate Found\n";
}
}
}
Try to code this psuedocode and post your attempt. Use
tags the next time.
For element = begin to end - 1 in array
// Range Check
if element is out of range
output element
continue next iteration
end if
// Duplicity Check
for temp = element + 1 to end in array
if temp == element // Check for the first match
output element // Output the match
return from loop // Return from duplicity check
end if
end for
end for
element = final element of array
if element is out of range
output element
end if
// No need to check for duplicities as this is the final element
So what is your problem?
ok now this code is working in a c++ project, but I dont understand this part:
#pragma comment(lib,"Releasetest4.lib");
It is a preprocessor directive telling the compiler to link the Releasetest4.lib library. Anyway I think this is supported only in the Visual Studio compiler. Therefore it is not encouraged. The best way is to use the "link" option of the compiler.
E.g. for Visual Studio
cl filename.cpp /link Releasetest4.lib
I compiled your program ( The one in your first post ) under the Visual Studio 2003 compiler and ran it. There was no problems for me. None of the changes in your last post were needed.
Check the Parts in Red. And post code within tags next time.
#include <iostream>
#include <math.h>
using namespace std;
int main () {
double k1;
double n1;
double tolerance;
int N;
double L;
double a, b;
cout << "Welcome to the Root Finding Calculator using the Bisection Method!" << endl << endl;
cout << "please enter a value for k1: ";
cin >> k1;
cout << "please enter a value for n1: ";
cin >> n1;
cout << "please enter the value for L: ";
cin >> L;
cout << "please enter an endpoint, a: ";
cin >> a;
cout << "please enter the other endpoint, b: ";
cin >> b;
cout << "please enter the level of tolerance: ";
cin >> tolerance;
cout << "please enter the maximum number of iterations to be performed: ";
cin >> N;
double FA = (a * (1 + (k1*n1)/(1 + (k1*a)))) - L;
double FB = (b * (1 + (k1*n1)/(1 + (k1*b)))) - L;
if ((FA * FB) > 0) {
cout << "Improper interval, try again!" << endl;
return 0;
}
for (int i = 1; i <= N; i++) {
double p1 = ((a + b)/2);
double FP1 = (p1 * (1 + (k1*n1)/(1 + (k1*p1)))) - L;
if (FP1 == 0 || fabs((b - a)/2) < tolerance) {
cout << "The root is " << p1 << endl;
return 0;
}
else { // You dont need this.
i += 1;
}
cout << "Iter " << …
I'm sorry about the indenting problem. I originally had the program written in word with indents and when I copied it to notepad so that I could open it from my email at school all the indents disappeared.
Dont use MS=Word to write code. Most of the the text formatting information in MS-word are lost when you copy t hem to notepad or another text editor.
Dont use notepad to write code unless you are writing a hello world program. If you are using Visual Studio there is a very good code editor in it that supports syntax highlighting, auto indenting... If you dont have Visual Studio, Dev-Cpp is a good free compiler with a code editor. Personally I use a seperate editor to write code as it loads quickly compared to onethat comes in a Development Environment. I use the IDE only for compiling, and even that I do in the command line when possible, but that depends on personal taste. Some good free editors that with syntax highlighting and auto indenting are Notepad++, TextPad. These are good even when you are programming in another language as most of the document classes are supported in them.
I also added the beginning of and end of loop comments, because my last program had so many brackets, I started getting confused as to what loops they belonged to. So I started adding the comments to prevent my confusion, not to annoy other readers.
If you use Auto indenting you …
I guess you could show a dialog with the required graphics in it's backgound at startup, on the WM_INITDIALOG event, or WM_CREATE event; set a timer at that moment, and when the timer throws the WM_TIMER event after the required time-interval, you can close the Splash Screen.
The problem was not with the binary to decimal conversion. It was with the usage of char( x ). Anyway if the usage is not correct, it is fine with me. The correct output for 100001 was pure coincidence I guess. Talk about luck.
Sine you are working in console mode it is a bit involved. Refer this page. It has the necessary functions to get the console window dimensions. You will have to calculate the required text position depending on the console width and height and then output the menu accordingly.
What you say about binary handling in computers is correct Dragon.
But what Server_Crash did, was not int n = "100001";
he did int n = 1000001; // this is correct.
What I don't get is how did
char( int n )
work. It gives you the correct character output. Is that a cast? or is there a function called char that takes an input of type int? It also can be a char constructor... :eek: This calls for Narue.
i get errors saying that the fucntions do not take zero parameters
#include <windows.h> #include <stdio.h> #include <string.h> #include <iostream.h> #include <stdlib.h> #include <conio.h> #include <process.h> struct Node { PROCESS_INFORMATION p; Node *next; }; Node* head = NULL; void addprocess(PROCESS_INFORMATION p1, Node *cur) { Node* t; t = new(Node); t->p = p1; t->next = head; head = t; }; void closeprocess(Node *head) { Node* t; t = head; while(t != NULL) { TerminateProcess(t->p.hProcess, 0); t = t->next; }; }; void menu (void) { int choice; do { cout << " ---1. Calculator ---" << endl; cout << " ---2. Notepad ---" << endl; cout << " ---3. Paint ---"<< endl; cout << " ---4. Terminate ---" << endl; cin >> choice; char lpApplicationName[100]; STARTUPINFO StartInfo; PROCESS_INFORMATION ProcessInfo; ZeroMemory(&StartInfo, sizeof(StartInfo)); StartInfo.cb = sizeof(StartInfo); if(choice == 1) { strcpy(lpApplicationName, "C:\\Windows\\system32\\calc.exe"); addprocess(); } if(choice == 2) { strcpy(lpApplicationName, "C:\\Windows\\system32\\Notepad.exe"); addprocess(); } if(choice == 3) { strcpy(lpApplicationName, "C:\\Windows\\system32\\mspaint.exe"); addprocess(); } if (choice == 4) { closeprocess(); } CreateProcess (lpApplicationName, NULL, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS|CREATE_NEW_CONSOLE, NULL, NULL, &StartInfo, &ProcessInfo); }while(choice != 4); } void main(void) { menu(); }
If you change the function definitions, then you should change the way you call them also. Correct the places I have highlighted in Red.
And why aren't you using the Node* cur
element in the addprocess
function? You have to use it if you want to link the processes to a link list that you have a handle to. I think it should be the …
#include<iostream>
using namespace std;
int main()
{
int count;
double grade, total, average;
grade = 0;
total = 0;
count = 0;
cout <<"\nTo stop entering grades. Type in the number";
cout <<"\n 999.\n\n";
do
{
cout <<"\nEnter a grade: ";
cin >> grade;
if (grade < 0 || grade > 100 && grade !=999)
{
cout <<"\n Invalid grade has been entered"
<<"\nPlease check the grade and re-enter";
}
else
{
if ( grade != 999 )
{
total = total + grade;
count++;
}
else
{
break; //break if 999 was entered
}
}
}
while(1); //this expression is always true
average = total / count;
cout << "\nThe average of the numbers is " << average << endl;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int count;
double grade, total, average;
grade = 0;
total = 0;
count = 0;
cout <<"\nTo stop entering grades. Type in the number";
cout <<"\n 999.\n\n";
total = total + grade;
cout << "Enter a grade: ";
cin >> grade;
count++;
while (grade != 999)
do
{
cout <<"\nEnter a grade: ";
cin >> grade;
if (grade < 0 || grade > 100 && grade !=999)
{
cout <<"\n Invalid grade has been entered"
<<"\nPlease check the grade and re-enter";
}
else
total = total + grade;
count++;
break; //break if a valid grade was entered
}
while(1); //this expression is always true
average = total / count;
cout << "\nThe average of the numbers is " << average << endl;
system("pause");
return 0;
}
Made the changes in red. Didn't check. Don't know if new bugs are introduced. You check.
um ok you said b4 that endif is not santax of c++ but in that site you gave me it is used many times
It is
#endif
man. Not just
endif
. Those are two different things. It is about time you bought one of those books in the list you asked for in this thread and read before asking any more questions.
t->p = [B]p1[/B];
What is this p1 inside the addprocess function?
struct Node
{
[B]info[/B] p;
Node *next;
};
What is the type called info inside the Node structure?
Does this code compile?
Anyway you should add the ProcessHandle returned in ProcessInfo
to the linked list. Otherwise you have no way of accessing the created process inside the closeprocess
function.
Just a rearrangement and modification of your original code. Look and learn.
#include <iostream>
using namespace std;
int main()
{
int count = 1, number ;
int Total = 0 ;
while (count <= 5)
{
cout << "Please input interger " << count << " : ";
cin >> number ;
if ( number % 2 == 0 )// % is the Modulus, it gives the remainder after dividing by 2.
{
Total = Total + number ;
}
}
cout << "Even Number Total is " << Total << endl ;
system("pause");
return 0;
}
Can't you see it near the "Quote Reply" and "Quick Reply" Buttons? See attached image on this message.
What do you mean you didnt get in on time?
The thread was started at 2.33 PM
You made that post at 2.46 PM
That is only 13 minutes.
bye. Hope to see you soon.
Better if you name this thread with something relevant. Like "Similarities between C++ vectors and Physics Vectors". That would describe the content better. Thanks for considering my request. :D
PS. Within 15 or 30 minutes of posting you can see the "Edit this Post" button.
enter m:
1
enter a value for k:
1
enter a value for n:
1
enter a value for L:
3
enter an endpoint a:
0
enter an endpoint b:
5
Enter the level of tolerance:
.001
enter the maximum number of iterations:
25
Monitor iterations? (1/0): 1
Iter 0: x = 2.5, dx = 2.5, a = 0, b = 5, f(x) = -0.5
Iter 1: x = 3.75, dx = 1.25, a = 2.5, b = 5, f(x) = 0.75
Iter 2: x = 3.125, dx = 0.625, a = 2.5, b = 3.75, f(x) = 0.125
Iter 3: x = 2.8125, dx = 0.3125, a = 2.5, b = 3.125, f(x) = -0.1875
Iter 4: x = 2.96875, dx = 0.15625, a = 2.8125, b = 3.125, f(x) = -0.03125
Iter 5: x = 3.04688, dx = 0.078125, a = 2.96875, b = 3.125, f(x) = 0.046875
Iter 6: x = 3.00781, dx = 0.0390625, a = 2.96875, b = 3.04688, f(x) = 0.0078125
Iter 7: x = 2.98828, dx = 0.0195313, a = 2.96875, b = 3.00781, f(x) = -0.0117188
Iter 8: x = 2.99805, dx = 0.00976563, a = 2.98828, b = 3.00781, f(x) = -0.00195313
Iter 9: x = 3.00293, dx = 0.00488281, a = 2.99805, b = 3.00781, f(x) = 0.00292969
Iter 10: x = 3.00049, dx = 0.00244141, a = 2.99805, b = 3.00293, f(x) = 0.000488281
Iter 11: x = 2.99927, dx = 0.0012207, a = 2.99805, b = 3.00049, f(x) = -0.000732422
Iter 12: x = 2.99988, dx = 0.000610352, a = 2.99927, b = 3.00049, f(x) = -0.00012207
The root is 3
f(3) = -0.0001221
Those are the values I get when I run for the above values of m, k, l ,n. At k = 1, and n = 1 and L = 3, the function reduces to f(x) = x( 1 + 1/(x + 1)) - 3
These are the values for the function f(x) = x( 1 + 1/(1 + x) )- 3
for the same values of x.
x f(x)
2.50000 0.21429
3.75000 1.53947
3.12500 0.88258
2.81250 0.55020
2.96875 0.71678
3.04688 0.79978
3.00781 0.75830
2.98828 0.73755
2.99805 0.74793
3.00293 0.75311
3.00049 0.75052
2.99927 0.74922
2.99988 0.74987
Clearly the values of f(x)
differ in your implementation. Check the code where you calculate f(x)
in your code.
Really? Care listing some of them here? For others to learn?
It has the ability obviously. But how can you convince that NAN is a number? It is not a number.
NAN is short for "Not A Number". You get this for values like infinity. Check the values of sss
and (s*s)+(ss*ss)
. Most probably either both of them are 0 or the (s*s)+(ss*ss)
value is zero. You should know already that 0 divided by 0 is undefined and any number defined by 0 is also undefined. You should check for these conditions before dividing.
Also use
when posting code.
Okay so you can handle that error now?
Comment out all the other irrelevant code in the loop and other irrelevent code after the loop so that only this remains.
for(i=0;i<=a.Height;i++)
{
[INDENT]for(j=0;j<=a.Width;j++)
{
[INDENT]Color c=a.GetPixel(i,j);[/INDENT]
}[/INDENT]
}
See if the error comes up again. If not, keep on adding lines until you get the error, and try to see what are the values of i and j this happens.
Does this happen at runtime or compile time?
You will have to read the image into a two dimensional structure, maybe a two dimensional array, and then apply the operations to corresponding elements at position x and y.
ResultantImage[x][y] = Image1[x][y] - Image2[x][y]
You could do this even with a single dimensional array, but that is rather unintuitive in my opinion.
As long as it pays me, and pays me well.
>> if its a character array then initialize it with '\0' and if its an integer array then initilize it with 0
I'm not about to revive that old thread you linked, so I'll do it here because I just can't resist the urge :twisted: . In the above, '\0' and 0 are identical because '\0' == 0. Personally, I prefer just plain 0 -- why? because its less typing.
char array[255]; memset(array,0,sizeof(array)); int array[255]; memset(array,0,sizeof(array);
Man ain't I learning today. I always used 0 blindly. Didn't know that \0 == 0 :eek: Thanks Dragon. :)
When you post C/C++ code, put the code inside tags like this,
[[/B][B]code[/B][B]]
#include <iostream>
int main()
{
std::cout << "Hello World\n";
return 0;
}
[/code]
and it will appear like this.
#include <iostream>
int main()
{
std::cout << "Hello World\n";
return 0;
}
You say this only after I finished memorising MSDN? sniff sob sob
Perhaps on your implementation, but the C standard says quite clearly that flushing an input stream is undefined, and flushall is a non-standard function.
Yeah my compiler Visual C 2003 allows clearing an input stream with
fflush
, and
flushall
. :sad: Thanks for the correction. Got to refer the Standard C documentation more, rather than MSDN.
well no duh statments dont bring help questions bring help
Then keep on asking, just as you are doing right now. It would be interesting to see how you get by.
as·set
1. A useful or valuable quality, person, or thing; an advantage or resource
I am not that good in theory, but you use the term stream for communications channels like a file, input/output device.
I see the problem now. When you typed the score 45\n
for example, scanf take the integer part for the score, and leaves the newline \n
in the stream. Therefore fgets
takes this remaining \n
as the input for the firstname: hence you see firstname:lastname
in the same line. It had nothing to do with clearing the array.
fflush()
flushes out all the remaining characters in the stream thereby clearing the stream of the remaining \n
.
The function flushall()
also does the same thing.
Repost the code with the memset function.
What would happen if you ran this code?
void List::ListMax()
{
recordptr temp = head;
recordptr max = head;
int maxAge = 0;
if(temp!=NULL)
maxAge = temp->age;
temp = temp->next;
while (temp!=NULL)
{
if ( temp->age > maxAge)
{
maxAge = temp->age;
max = temp;
}
temp = temp->next;
}
if ( max != NULL )
cout << max->age;
}
cool thanks guys it worked and as far as the tutorial walkthroughs and samples i have all ready read them but i dont compleatly understand them mostly i have a tendency to `look so far ahead of the situation in to the abstract that i dont know whats happening in the present but i understand alot of it but i just need a picture of structure for the santax of the coding and if u guys know of any other tutorial websites in witch i could understand them better pleas tell me for example i wouldnt need c++ for dummies i would need c++ for dummies for dummies ok so thanks
Maybe I am just being too picky, but are both the period keys of your keyboard broken? :confused:
Wow! what a screwed-up mess that can become! I would be tempted to change careers every quickly.
Yep. I know I did. :D
I guess you can find a lot about the JPEG files specs and the BMP files specifications if you google for it. Just searching for "BMP image format" and "JPEG image format" would do.
that is not the right formula either, but it has the right idea. Entering the numbers from the keyboard will get very very timesome if you have to run the program quite a few times for debugging and testing. -- better to just hard-code the numbers in the program or save them in a file, makes debugging a whole lot easier.
you need two float variable -- numerator and denominator.
float numerator = 0, denominator = 0; vector<float> array; for(i = 0; i < array.size(); i++) { numerator *= array[i]; denominator += array[i]; } float result = numberator / denominator;
No I guess it is correct. I should have been a bit generic when explaining my simplification of the formula.
It is only when there is two resistances that R becomes R=(R1*R2)/(R1 + R2 )= ( Product / Addition )
For 3 resistances R=(R1)*(R2)*(R3)/(R1*R2+R2*R3+R3*R1 )
For 4 Resistances R=(R1)*(R2)*(R3)*(R4)/(R1*R2*R3+R2*R3*R4+R3*R4*R1 + R4*R1*R2 )
...
As you can see this gets tedious ( but not impossible; just the use of some permutations and combinations) to simplify when the number of resistances involved get larger. So the easiest way is to add the reciprocals and take the overall reciprocal as the final answer.
But as Dragon pointed out, it should be checked for division from zero and overflow, and possibly underflow. A more refined approach of ani_manit would do, with the values entered from a text file.
Because I have to create new folders frequently these days, I googled a bit and came up with this cool tool called bxNewFolder .
bxNewFolder adds a "New Folder" button to the toolbar of Windows Explorer. It also provides a hotkey (F12) to create a new folder within the Explorer quickly. Also it keeps a log of the folder names created before, so it is very usefull when creating identical directory heirarchies.
I'm no math whiz but isn't that formula the same as
R =1 / (r1 + r2 + ... rn)
No it isn't.
Take for example two resistances. That is the simplest case. 1/R = 1/R1 + 1/R2
=> R = (R1)(R2)/(R1 + R2 )
I wouldn't bother learning win32 (sorrie wolfie), waste of time in my opinion. Look to C# and the .net environment.
Hell I should concentrate more on answering some generic C/C++ questions. :cheesy: