|
How did you declare dialogs?
|
|
|
|
|
Check for Dialog IDD if they matching change them.
-@SuDhIrKuMaR@-
|
|
|
|
|
Can anyone advise with this?
I am tring to write a MFC dialog application that displays a window that says "Hello" when the program is run, and has an OK button and a Cancel button. The screen will close when either of the buttons are clicked. Im not sure how to do this on Visual C++ 2008.
|
|
|
|
|
You can use of MessageBox and you can set for it Ok,Cancel Or yes/no.
|
|
|
|
|
You want Yes and NO on the message box you are displaying.
-@SuDhIrKuMaR@-
|
|
|
|
|
I'm tring to write a recursive function that takes as a parameter a non-negative integer and generates the following pattern of stars if the integer is 4.
*
* *
* * *
* * * *
* * *
* *
*
#include <iostream>
#include <iomanip>
#include<fstream>
using namespace std;
int func(int x);
int main(int argc, char *argv[])
{
func(4);
system("PAUSE");
return 0;
}
int func(int x)
{
int i;
if (x>=0)
func(x-1);
for (i=1; i<=x; i++)
{
cout<<"* ";
}
cout << endl;
return 1;
}
Above code gives me
*
* *
* * *
* * * *
Below code gives me
* * * *
* * *
* *
*
#include <iostream>
#include <iomanip>
#include<fstream>
using namespace std;
int func(int x);
int main(int argc, char *argv[])
{
func(0);
system("PAUSE");
return 0;
}
int func(int x)
{
int i;
if (x<=3)
func(x+1);
for (i=1; i<=x; i++)
{
cout<<"* ";
}
cout << endl;
return 1;
}
How do I put these codes together to get
*
* *
* * *
* * * *
* * *
* *
*
|
|
|
|
|
codedecode wrote: How do I put these codes together ...
How about just calling both methods?
/ravi
|
|
|
|
|
Then it won't be a recursion, just a double call
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: Then it won't be a recursion,
He's already implemented each call using recursion.
So it's a matter of calling each recursive method sequentially (which could also be done recursively, if the instructor insists on being pendantic).
/ravi
|
|
|
|
|
Please forgive me, I am new to coding. What do you mean by call both methods?
|
|
|
|
|
It seems you've implemented each method (to print rising and falling stars) recursively, so imho you've satisfied the recursion requirement.
Now, instead of implementing the functions in separate programs, why not package them in the same program (you'll have to rename one so their names don't clash) and simply call both functions from your main program?
/ravi
|
|
|
|
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int func(int x);
int main(int argc, char *argv[])
{
func(4);
system("PAUSE");
return 0;
}
int func(int x)
{
int i;
for (i=1; i<=x; i++)
{
cout<<"* ";
}
if (x>=0)
func(x-1);
for (i=1; i<=x; i++)
{
cout<<"* ";
}
cout << endl;
return 1;
}
Graham
Librarians rule, Ook!
|
|
|
|
|
This outputs
* * * * * * * * * *
*
* *
* * *
* * * *
Which is more than what I could get.
|
|
|
|
|
The problem with the code given is that he only uses one cout<<endl at the end of the function, so all the first stars are coming in the same line, try adding a cout<<endl before the if at the end of the first for. (Or maybe in other position, but you need it)
EDIT: You might also need to change the order of the fors
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
You are correct. I added another <<endl and changed some numbers a little, as you can see below, and got the correct result. Thank you all very much.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int func(int x);
int main(int argc, char *argv[])
{
func(0);
system("PAUSE");
return 0;
}
int func(int x)
{ int i;
for (i=0; i<=x; i++)
{
cout<<"* ";
}
{
cout << endl;
}
if (x<=2)
func(x+1);
for (i=1; i<=x; i++)
{
cout<<"* ";
}
cout << endl;
return 1;
}
Now I need to add a program that prompts the user to enter the number of lines in the pattern and then use the recursive code above to generate the pattern. Any thoughts?
I have tried to add the code below but get errors.
cout<<"Enter a number between 4 and 10: ";
cin>> int x;
cout<< endl;
|
|
|
|
|
Yes, sorry about that. Apart from the missing cout << endl; line already mentioned it gives the following output
* * * *
* * *
* *
*
*
* *
* * *
* * * *
I can provide a recursive function if you relax the requirement for it to take only one parameter:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int func(int x, int y);
int main(int argc, char *argv[])
{
func(1, 4);
return 0;
}
int func(int x, int y)
{
int i;
for (i=1; i<=x; i++)
{
cout<<"* ";
}
cout << endl;
if(x != y)
{
func(x + 1, y);
for (i=1; i<=x; i++)
{
cout<<"* ";
}
cout << endl;
}
return 0;
}
Graham
Librarians rule, Ook!
|
|
|
|
|
You are right. This works as well. Even better actually. You have helped out greatly. Thank you.
Do you know how to promt the user to enter the number of lines in a pattern and will use the recursive code to make the pattern?
I tried the below code and got errors.
cout<<"Enter a number between 4 and 10: ";
cin>> int x;
cout<< endl;
|
|
|
|
|
You should declare the variable before, and then assign the value.
int x = 0;
cout<<"Enter a number between 4 and 10: ";
cin>>x;
cout<<endl;
and then call the function
func (x)
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
That works. I just need to change some stuff around.
If I enter 0 I get
*
* *
* * *
* * * *
* * *
* *
*
If I enter 4 I get
* * * * *
* * * *
If I enter 10 I get
* * * * * * * * * * *
* * * * * * * * * *
I think that needs to be if 10 is entered.
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
|
|
|
|
|
Don't understand. I've changed the main function to be
int main(int argc, char *argv[])
{
int x = 0;
cout<<"Enter a positive number: ";
cin>>x;
cout<<endl;
if(x > 0)
func(1, x);
return 0;
}
and everything works fine (the check for a positive, non zero number is to avoid extremely large loops)
Graham
Librarians rule, Ook!
|
|
|
|
|
Hi,
The following works with a static and is fully recursive
void ShowTree(int iSize)
{
if(iSize > 0)
{
static int ilevel = 0;
ShowTree(-(++ilevel)); std::cout << std::endl;
ShowTree(--iSize);
ShowTree(-(--ilevel)); std::cout << std::endl;
}
else if(iSize < 0)
{
ShowTree(++iSize);
std::cout << "*";
}
}
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
hello for all
how can i store numberic result (int, float any number) in string varibales
|
|
|
|
|
There are a number of ways, depending which type of string you are using.
For std::string
#include <sstream>
std::ostringstream temp;
temp << value;
std::string result(temp.str());
</sstream>
For CString
CString str;
str.Format("%.1f", floatValue);
str.Format("%d", intValue);
For c null terminated strings use:
char str[50];
_snprintf(str, 50, "%.1f", floatValue);
_snprintf(str, 50, "%d", intValue);
sprintf can also be used in the last example but it is less safe than _snprintf (it can lead to buffer overruns with the supplied buffer isn't large enough)
Graham
Librarians rule, Ook!
|
|
|
|
|
int s=0;
int result[50];
string ggg[50];
i want stror result[s] in ggg[s]
|
|
|
|
|
std::ostringstream temp;
temp << result[s];
ggg[s] = temp.str();
Graham
Librarians rule, Ook!
|
|
|
|