Prabakar 77 Posting Whiz

For some reason I was never notified that you have replied.

And yes, I used it to get '\n' in the first program. In the second program I forgot to delete it:P

Prabakar 77 Posting Whiz

do you mean equivalent reference variable?

Prabakar 77 Posting Whiz

Well the .bmp file explain it. I guess my the code should work fine.
flag is just a variable that I set to false(0) initially & if 7 or the point is reached flag is set to true(1) & hence exits out of the loop. you can set something like this too
int flag = 0 ;
and set it to 1 when conditions are met so that you can exit the loop
So is this code ok?

#include <iostream>
#include <time.h>      
int main()
{
    srand (time(NULL));
    using namespace std;
    int d1, d2;
    int suma = 0, punto = 0;
    char game;
    cout << " Wanna start ?? \n";
    cout << " 1 - YES, OF COURSE jeje\n";
    cout << " 2 - NO, GET ME OUT OF HERE\n Your Choice: ";
    cin >> game;
    while (game != '2')
    {
         cin.get() ;
         d1 = rand () % 6 + 1; 
         d2 = rand () % 6 + 1; 
         cout << "\n first dice is...  " << d1 << "\n\n";
         cout << " second dice is...  " << d2 << "\n\n";
         cout << " the sum up is... " << (suma = d1+d2) << "\n\n";

	switch (suma)
	{
	case 11: case 7:
            cout << " YOU WON \n\n";
	    break;
	case 2: case 3: case 12:
	    cout << " YOU LOST \n\n";
	    break;
	case 5: case 4:	case 6: case 8: case 9: case 10:
	    cout << " " << suma << " is your point \n\n"; …
Prabakar 77 Posting Whiz

Did you run my program?
I hope removing unnecessary output statements should help you get the desired output:)

Prabakar 77 Posting Whiz

I still don't understand part of the game. Is this what the game should do?

#include <iostream>
#include <time.h>      
int main(int argc, char* argv[])
{
    srand (time(NULL));
    using namespace std;
    int d1, d2;
    int suma = 0, punto = 0;
    char game;
    cout << " Wanna start ?? \n";
    cout << " 1 - YES, OF COURSE jeje\n";
    cout << " 2 - NO, GET ME OUT OF HERE\n Your Choice: ";
    cin >> game;
    while (game != '2')
    {
         cin.get() ;
         d1 = rand () % 6 + 1; 
         d2 = rand () % 6 + 1; 
         cout << "\n first dice is...  " << d1 << "\n\n";
         cout << " second dice is...  " << d2 << "\n\n";
         cout << " the sum up is... " << (suma = d1+d2) << "\n\n";

	switch (suma)
	{
	case 11: case 7:
            cout << " YOU WON \n\n";
	    break;
	case 2: case 3: case 12:
	    cout << " YOU LOST \n\n";
	    break;
	case 5: case 4:	case 6: case 8: case 9: case 10:
	    cout << " " << suma << " is your point \n\n";
	    punto = suma ;
	    bool flag = false ;
	    do
	    {
	        cout << " Press Enter to throw again... ";
                cin.get() ;
                d1 = rand () % 6 + 1;     // to dice start randomly
		d2 = rand () % 6 + 1;     // to dice start randomly
		cout << "\n first dice is...  " << d1 << "\n\n";
		cout << " second dice …
Prabakar 77 Posting Whiz

I believe do-while will serve you better than while(). You need not repeat 25 - 29 if you use do-while loop
Could you explain how the game works? so that I can think of a solution.

Prabakar 77 Posting Whiz

>>For the same reason that doing p++ advances by one unit of whatever the pointer is pointing to, not by 1 byte of memory.

Does this operation require the use of sizeof operator? & please look at my previous post, I have edited it.

Prabakar 77 Posting Whiz

"&x[1]" doesn't the compiler uses sizeof to evaluate this expression?
Since I am not sure of this. I think unions can be used to find the answer

I wrote this program & it seems to work.

#include<stdio.h>
int main ()
{
    union findsize
    {
          unsigned char c[8] ;
          int a ;
    } obj;
    int i, bytecount = 0 ;
    obj.a = -1 ;
    for ( i = 0 ; i < 8 ; i++ )
        if ( obj.c[i] == 0xff )
            bytecount++ ;
    printf ( "%d", bytecount ) ;
    getchar();
    return 0 ;
}
Prabakar 77 Posting Whiz

>> int totalLen = strlen(formatstr) + strlen(name);
"%s" will be counted. The totalLen should be 41 but obtained totalLen is 43.
And,
>> len = sprintf(NULL,"This is my forename: %s",fname);
seems to work perfectly!!!
Is there an assurance that the string will not be written if NULL is passed? I believe not. Is this undefined behavior?

Prabakar 77 Posting Whiz

Thanks for the code, I guess It will take me sometime to understand the code.

Prabakar 77 Posting Whiz

I have seen this code before. It was written by Kanetkar in a book dedicated for the turbo c complier.


In my first glance I found these.
1) some of the codes are missing. ( initgrraph(), etc which will make a interrupt )
2) malloc returns a void pointer which needs to be type-casted.
3) stdlib.h, conio.h required.
4) no arguments for exit().
and more.
Besides, Why should you used such old compilers & its nonstandard libraries?

Prabakar 77 Posting Whiz

>> g = x ;
g has to be least of the 2 numbers rather than simply x for the code to be faster.
Why brute force?

Prabakar 77 Posting Whiz

Please attach the loadObj.h file. I know I can't help you, but I believe I can learn from you.

Prabakar 77 Posting Whiz

The problem doesn't even need an array, nevermind a sorted one.

Yes, doesn't need one, but insist on having one.

Prabakar 77 Posting Whiz

I still believe your first suggestion of getline() is better

Prabakar 77 Posting Whiz

I don't understand why getline() did not work.
Here is a code that uses getline as lener suggested.

#include <iostream>

#define isupper(a) ((a)>= 'A' && (a)<= 'Z') 
#define islower(a) ((a)>= 'a' && (a)<= 'z') 

using namespace std ;

int main()
{
    char PlainText[100], CipherText[100] ;
    cin.getline(PlainText, 100) ; 
    for ( int i = 0 ; PlainText[i] ; i++ )
    {
        if ( isupper(PlainText[i]) )
            CipherText[i] = 25 - (PlainText[i] - 'A') + 'A' ;
        else if ( islower(PlainText[i]) )
            CipherText[i] = 25 - (PlainText[i] - 'a') + 'a' ;
        else CipherText[i] = PlainText[i] ;
    
    }
    cout << CipherText ;
    cin.get();
    return 0 ;
}

EDIT:

string class could be used rather than array of char.

Prabakar 77 Posting Whiz

1)cin reads a array of char until a delimitter like <space> or <new line> is encountered. Thats why the program might have stoped after chaging the first letter.

2)The converstion you've made could be done by math exprestions rather than that many if struct.

Hope this helps:)

Prabakar 77 Posting Whiz
for ( exp = 0, resultado = 1 ; exp < exponente ; exp++ )
    resultado *= base ;
cout << " The result is: " << resultado;

Is this what you are looking for?

Prabakar 77 Posting Whiz
void squares(int n)
{
    if( n== 1 ) 
        cout << 1 ;
    else
    {
         cout << n*n << " " ;//swap lines 7 & 8 for ascending order
         squares ( n- 1 );
    }
}
Prabakar 77 Posting Whiz

Array index starts with 0 & there is a total of 8 elements. So, the first no to be checked is (7-0)/2 = [3]. The second is 3+(7-3)/2 = [5].

Prabakar 77 Posting Whiz

@Vijayan

Sorry for not replying soon. I was out for a 4 day tour & only had time to enjoy. Thank you for posting. It is very helpful.

Prabakar 77 Posting Whiz

I had been searching with Google, but I did not find anything other than the hook up method that Williamhemsworth used(the link I gave). You need to have some patience. Perhaps someone else can help you.

Prabakar 77 Posting Whiz

You can make your program to sleep

This link may be useful

Prabakar 77 Posting Whiz

To hide the console window check this
For the user clicking on the desktop here is a win32 Program

Prabakar 77 Posting Whiz

Two years ago, I wrote a peace of junk which managed to solve the puzzle. I lost the code. But I can say what I did.
I had a 9X9 matrix. At the beginning any of the 1-9 numbers can possibly occupy any of the 81 cells. When the user finish entering the constraints. I just iterated a loop over & over again until the answer is found.
The loop checks the following cases for all numbers between 1-9 in all the cells. I will talk with the number 1 for simplicity

1) Is 1 the only possible number that can occupy the cell?
2) Is this the only place where 1 can appear in that column?
3) Is this the only place where 1 can appear in that row?
4) Is this the only place where 1 can appear in that 3x3 box?
and a few more logics.

If any one of the conditions are satisfied then 1 will be eliminated from the possibility list of the other cells in the same column, row & box.

It did work but as I said before it was a crappy code.

But Free source codes are available. Just Google for it and see how many answers you get.

If you want the code to be genuine then you may start with your own logical explanations for the puzzle.

Prabakar 77 Posting Whiz
Prabakar 77 Posting Whiz

I have read about Object Serialization in my JAVA book. Could it be possible with C++?

Prabakar 77 Posting Whiz

The input is not pointer to long int but long int.

When we declare int a;
the compiler assumes the following.
auto signed [long or short] int a ;

In that code you want it to be in registers,
but compiler can not assure you that as Dave said
As far as I know Only in Turbo c++ compiler int defaults to auto signed short int(May be because it is a 16-bit compiler). But in many other compilers int defaults to auto signed long int
That is why the code is correct

I may well be wrong though, You may wait for some experts to clarify.

The problem with the first function may be the problem pointed by Salem If 2's compliment is not used then the code is wrong.

Prabakar 77 Posting Whiz

Thanks for your reply:)

I still don't understand 2 things. Please explain them too

1:

The address of a constructor shall not be taken.

- I am not getting it.
2:

would this not cause a leak?

- What is a leak? How is it caused by that code?

Prabakar 77 Posting Whiz

The do-while loop in the original post was being used to cycle through the letters of the string to see if any of them was an 'i'.

And it does? If the first letter is 'i' No way the program ends. If the first letter is not 'i' even if 'i' is present somewhere else in the string it will just ignore it.

Prabakar 77 Posting Whiz

My guess:
calling an object's constructor will create a temp object which will be destroyed immediately
and :: is used to instruct the compiler that you are not referring the fn SubFoo() of the base class.
Am I right?

Prabakar 77 Posting Whiz

Foo foo = new Foo().SubFoo();
SubFoo: maybe sub class or independent class, but not method.

How could this ever be. SubFoo() is a function. Perhaps, it may be a default constructor, but that doesn't mean that it is not a function. A constructor is a special function that will called when a object is created.

The only other alternative I could think of is that subfoo() is a macro used in the worst possible way.
#define subfoo() something

what i need is,
the code must call SubFoo constructor, and return Foo object (by automatically cast)

Can a constuctor return a object?

Foo Foo::SubFoo() const { return ::SubFoo() ; }

Could you please explain me how the code calls SubFoo constructor.

Prabakar 77 Posting Whiz

Sorry, but the original program has exactly the same effect: see do-while loop in the original post...

May be the original program is supposed to have the same effect

Prabakar 77 Posting Whiz

My guess:
1)The function checks whether the integer a is divisible by 8.
2)The use of new which is not an operator in c but in c++.

Prabakar 77 Posting Whiz

I guess I edited the post before you replied. Please excuse me, English is not my mother tongue & its a little difficult to frame a sentence that would mean what I think. I just want to know about .Net

Prabakar 77 Posting Whiz

ehh, what the hell ? for some reason my post is before yours, even though i was answering yours :S

Happens to me sometimes.

Prabakar 77 Posting Whiz

So many languages are used widely in industries & I have not even heard of some of those languages. My head is swinging.

What is .Net? Is it a language? I have heard people say VB.Net, ASP.Net, C#.Net, etc. What do they mean

Prabakar 77 Posting Whiz

In Java, as far as I know, you can't have an array start in the MIDDLE of another array like you can in C++. So in this case in Java you'd have to create three arrays and set aside separate memory for three arrays and do a copy from the original array to the other two arrays.

How about using 3 integers that resembles the index.
all_stud = 0 ;
fail_stud = 0 ;
pass_stud = numFailStud ;
and access allScores[pass_stud+i] or something like that.
Works with both language, though I know it cant completely replace the need of pointers.


Are C++ & JAVA the only 2 dominant language in the industry? If yes why not any other language like BASIC. If no, what are the other languages used?
I want to know this. Please

Prabakar 77 Posting Whiz

Yes indeed I use that a lot

case 'n': case 'N': /* something */break ;
case 'y': case 'Y': /* something */break ;

Prabakar 77 Posting Whiz

I was not sure what I gave was right, so I did say my source partially. Its a book devoted to turbo C++.

You saw through it. Yes indeed. I was subjective. I knew it too.

I did not add break, because it is not a must in switch case.

Thanks for your post I got valuable informations.

Prabakar 77 Posting Whiz

Great! No error No warning. The only problem was to search for the hidden window in task manager. Works great!

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <wincon.h>
int main()
{

    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);
    system ( "start firefox www.daniweb.com" ) ;
    Sleep ( 2000 ) ;
    ShowWindow(hWnd, 1 ) ;
    return 0 ;
}

I am working with Windows XP so should not I use 0x501?

Prabakar 77 Posting Whiz

Now I get this,

||=== Hide, Debug ===|
F:\Programs\VC\Hide\main.cpp|2|warning: "_WIN32_WINNT" redefined|
D:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\windef.h|20|warning: this is the location of the previous definition|
F:\Programs\VC\Hide\main.cpp||In function `int main()':|
F:\Programs\VC\Hide\main.cpp|7|error: `GetConsoleWindow' undeclared (first use this function)|
F:\Programs\VC\Hide\main.cpp|7|error: (Each undeclared identifier is reported only once for each function it appears in.)|
||=== Build finished: 2 errors, 2 warnings ===|

Add I do not know why I have to define _WIN32_WINNT, please do explain that too.

Prabakar 77 Posting Whiz

is Rep Power == Rep-Altering Power?

Prabakar 77 Posting Whiz

I saw the functionn GetConsoleWindow() in MSDN but I am unable to use it in both the compilers I have ( Dev C++ & Code::Blocks ) Please Help

Prabakar 77 Posting Whiz

Others answers are wrong.
Never use System() on Win32 (creates another PAS)
Use Shell apis.

ShodoNinja never said it is a Win32 program

Prabakar 77 Posting Whiz

I heard heap in c++ lexicon is freestore

Prabakar 77 Posting Whiz

Not long before did a similar thread arise. If you want to hide a window then you should use WIN32 rather than console as far as I know.

Prabakar 77 Posting Whiz

I read this is in a book.

Switch case is faster if there are more than 2 conditions to be checked, since it maintains a table of pointers to execute instruction. And the table is created in compile time and hence case cannot contain variables unlike if else.

And also switch case looks good.

switch (var)
{
case 1:
    // do someting
case 2:
   // do something else
// more cases
}

or 

if ( var == 1 )
{
    // do someting
}
else 
{
    if ( var == 2 )
    {
    }
    else
    {
         // nest & nest & nest
    }
}
Prabakar 77 Posting Whiz

"Hide the dos window" - is it possible? I don't know.
If you want to close the dos window right after opening Firefox then a simple return 0 following system() should work.

Prabakar 77 Posting Whiz

a infinite loop with switch case perhaps