tux4life 2,072 Postaholic

It works the same way in C89. That's why int numbers[100] = {0}; sets all 100 numbers to 0 instead of just the first one and leaving the rest indeterminate.

Yes, but first: in C89 it's not called a designated initializer, and second: it doesn't get all those zeroes "by default", as already told by jephthah, they're automatically initialized to zero because you initialized the first element.

tux4life 2,072 Postaholic

A moderator hasn't told me that I've done anything wrong yet. Besides, the announcements are specific about homework without showing any effort. That's not the case here. The "Read this first!" even says that giving away answers is subjective.

If you want me to change how I post, you have to tell me exactly what I'm doing wrong and how you would do it the right way. Then convince me that your right way is better than my right way.

It could be that a moderator hasn't told you, but I hope you agree with me that if you're saying that, then you're just provocating any member on this forum, are you maybe thinking that you're a God or something? Do you want to wait till the very latest moment?
You've to understand that we're just warning you.

BTW, Is it that difficult to read a block of text?

Don't give away code!

You might feel inclined to help someone else. That's great! But don't solve the problem for them. Our goal is to help people to learn, and giving away answers doesn't achieve that goal. Naturally giving away the answer is a subjective thing, so just make sure that the person you help can't just take your code and turn it in for a grade. We want the people we help to do enough work to learn something meaningful.

(Source: http://www.daniweb.com/forums/thread78223.html)

I marked the most important in RED, do you understand it now?

tux4life 2,072 Postaholic
struct test
{
    int first;
    int second;
    int third;
};

struct test a = {0, 0, 1}; /* Old way */
struct test b = {.first=0, .second=0, .third=1}; /* New way */

Seems like the new way is always longer if you want to initialize all the variables :P

>Designated initializers are a C99 feature. To use them you need to have a compiler that allows C99.

No, are you serious? I mean: are you kidding?

>Structures, or any other variable, are not initialized to zero or any other value "by default"
Agreed, if we're talking about C89, but if you use designated initializers (C99) then the struct's data members (which weren't explicitly initialized) are automatically initialized to zero, check it out for yourself here:
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=215

:)

tux4life 2,072 Postaholic

Noooo! Not system("pause") again :(
I get tired of saying it: use cin.get(); instead :)
(explanation)

tux4life 2,072 Postaholic

>ya ur right i shouldn't have given him the code.What shall i do now?
Just read the forum rules and make sure that it doesn't happen again :)

tux4life 2,072 Postaholic

This ebook is the most suitable for you I think, superb explanations, cool code examples, answers to most of your C++ questions... :)

tux4life 2,072 Postaholic

Use typeid keyword.

cout <<  typeid(p).name();

And include the typeinfo header: #include <typeinfo> :)

tux4life 2,072 Postaholic

Hey iamthwee, why always neg-repping siddhant ?
Because you don't understand the formulas he's using ??

tux4life 2,072 Postaholic

On MinGW on Windows it's at least compiling, Dev-C++ also uses MinGW ...
And yes, remove the std:: as VernonDozier says :)

tux4life 2,072 Postaholic

You don't need to put this line:

using namespace std;

Rename your class to something besides std and the error will go away.

Here's my solution (just a simple example):

#include <iostream>
using namespace std;

class std
{
enum {A = 1, B, C};
public:
    std::std() { cout << A << endl; }
};

int main()
{
    std::std t; // create an instance of class 'std'
    return 0;
}

:P

tux4life 2,072 Postaholic

thanks the task is done.
thank you all for your cooperation.

Wow, and that after a year :P

tux4life 2,072 Postaholic

The Complete Reference: C++ (from Herb Schildt) is also a superb book !!
See it on amazon: http://www.amazon.co.uk/C-Complete-Reference-Herbert-Schildt/dp/0072226803/ref=sr_1_1?ie=UTF8&s=books&qid=1245598860&sr=1-1 :)

tux4life 2,072 Postaholic

>now it's not just shutting down
But where did you wrote the code to shut down the PC? You haven't.
Your coding style is rusted. Have a look at this guide to improve.
Especially read the 2.3 and 2.5 section of this guide.

You forgot the link: http://siddhant3s.googlepages.com/how_to_tell_rusted_cpp.html :P

tux4life 2,072 Postaholic

>BTW, why don't we give away free code, just curious?
How do you think that someone can become a programmer if he even doesn't write code himself?

tux4life 2,072 Postaholic

This would do it...

#include <iostream>
#include <string>

 using namespace std;
  int main()
 {
      char Team1[40];
      char Team2[40];
      int score1;
      int score2;
      
      cout << "enter the name of the two teams" << endl;
      cout << "Home Team: ";
      cin >> Team1;
      cout << "\nGuest Team: ";
      cin >> Team2;
      cout << "Enter scores (Home team Guest team): " << endl;;
      cin >> score1;
      cin >> score2;
      if(score1 < score2) {
                cout << "Guest" << Team2 << " won" << endl;
      }
      if(score1 > score2) {
                cout << "Home team "<< Team1 << " won" << endl;
      } if(score1 == score2){
             cout << "It was a tie" << endl;
             }
      system("pause");
      return 0;
}

To kangarooblood:
Do you want me to become angry :angry: ?
You MUST read the forum rules first (We don't give away free code here!!)
Before replying to a thread: read the whole thread, in that case you would have seen that this problem is already solved!
As mentioned in this post (of this thread) and in this post of a recent thread started by you: Don't use [B]system("pause");[/B] , but what do you do? You still continue using it, you even don't read your threads careful! :(

tux4life 2,072 Postaholic

First some remarks on your code:

  • Where are you using these libraries in your code?
    #include <windows.h>
    #include <cstdlib> // for system("pause"); junk
    #include <conio.h>
    #include <stdio.h>
    #include <sstream>
  • BTW, instead of creating a variable for each field, like this:
    char Csquare1('1');
    char Csquare2('2');
    char Csquare3('3');
    char Csquare4('4');
    char Csquare5('5');
    char Csquare6('6');
    char Csquare7('7');
    char Csquare8('8');
    char Csquare9('9');

    An array is the more common way to do that, e.g.:

    char board[9];
  • It's better to avoid using system("pause");

    Use cin.get(); as a replacement of system("pause"); , less typing and more portable :) !!

    Check out this if you want to know why :)

:)

tux4life 2,072 Postaholic

So, what's stopping you from marking this thread as solved?

tux4life 2,072 Postaholic

>i mean give letter B value smaller than the value of the letter A , is it possible ?
Yes.

>and what is the real benifet of the enumeartion in general ?
Consider this:

enum animal {CAT, DOG, FISH, COW};
animal a = FISH;

if( a == FISH )
{
    cout << "The animal is a fish..." << endl;
}

See the benefit?

>sometimes when making "cout" statement , the value appears as integers , is there any way that allow as see the real value of it , i mean when saying...
>i want the output here to be C not 4

Can you give a full example (keep the code as short and sweet as possible), which demonstrates this?

Hope this helps!

tux4life 2,072 Postaholic

Firefox, because of it's broad support for plugins :)

tux4life 2,072 Postaholic

Can anyone help me or guide me with the code please?

What do you think we're trying to do?

You only have to keep one thing in mind: We don't like it when you ask the same question numerous of times on different forums...

tux4life 2,072 Postaholic

>I'm gonna guess TurboC running on top of XP just for the hell of it.
Trust me, he is :)

To the OP:
If you really need conio, go and get a decent compiler like MinGW and use this conio implementation for it :)
That would already be a lot better !

tux4life 2,072 Postaholic

It's better to avoid using system("pause");

Use cin.get(); as a replacement of system("pause"); , less typing and more portable :) !!

Check out this if you want to know why :)

tux4life 2,072 Postaholic

Did someone actually notice that the OP's problem was already solved in this post ??

tux4life 2,072 Postaholic

And so far nobody has told you that it's better to avoid using system("pause");

Use cin.get(); as a replacement of system("pause"); , less typing and more portable :) !!

Check out this if you want to know why :)

tux4life 2,072 Postaholic

Don't use void main() :angry: !!!!!!!!
Read this if you don't understand why :)

tux4life 2,072 Postaholic

There's no need in posting the same thing twice, I have already answered your problem in post #8 of your thread :)

tux4life 2,072 Postaholic

Look at line 18: if(fp=NULL) , you assign the value NULL to a pointer, using a NULL pointer is a very dangerous thing to do, you probably meant: if(fp=[B]=[/B]NULL) :)

if(fp==NULL)  // changed assignment to comparison
    printf("Error\n");

Hope this helps!

Edit:: What you need is a good code formatting guide, like this one or AStyle, a program which automatically formats your code...

tux4life 2,072 Postaholic

Please don't mind reading my previous post, just read this article:
http://notepad-plus.wiki.sourceforge.net/NppExec+Compiler+Guide :P

Salem commented: Gotta love the simplicity of it all +35
Moschops commented: That was an excellent pair of posts :) +9
tux4life 2,072 Postaholic

hello there. i've installed mingw compiler and im wondering how i would go about setting up notepad++ to compile my c/c++ code?. How do i do this?

-regards.

I assume that the g++ command is in your PATH and that your environment variables are set correctly.

Then follow these steps:

  • Create a simple batch file called compile.bat which contains the following:
    g++ -o %1 %2
    PAUSE
  • Save it in the same directory as your C++ source file.
  • In Notepad++, you open the Plugins menu > NppExec > Follow $(CURRENT_DIRECTORY)
    (or you just press F5), a little dialog pops up, click the ... button and browse to the directory where your source file (and thus your batchfile) is in, select the batchfile (compile.bat) and click on Open, the path to your batchfile is now added to that textbox, now you have to put quotes (") around it, a little example:

    Let's say that the path to your batch file is: C:\compile.bat , then after putting quotes around it it becomes [B]"[/B]C:\compile.bat[B]"[/B] , after that you type the name you want to give to your executable file, for instance myprogram.exe, and thereafter (seperate those two with a space) you type the name of your C++ source file, for example: mysrc.cpp, the whole line would then be:

  • [B]"C:\compile.bat" [I]myprogram.exe[/I] [I]mysrc.cpp[/I][/B]

Hope this helps :)

tux4life 2,072 Postaholic

>please help me ?
If you post using code tags.

>tell me why code is not work correctly ?
Analyzing code without code tags goes far beyond my skills...
If you'd followed the steps described here while developing your program, your program should work fine now, but apparently you didn't :(

tux4life 2,072 Postaholic

Hey jephthah, since when can we use single quotes for c-strings?

case 1: printf("\n%s\n", 'one'); break;
case 2: printf("\n%s\n", 'two'); break;
case 3: printf("\n%s\n", 'three'); break;
case 5: printf("\n%s\n", 'five'); break;
case 11: printf("\n%s\n", 'eleven'); break;

:P

tux4life 2,072 Postaholic

First: I'm not asking how to do this, just carry on...
Hey, I found a nice link on how to read C/C++ declarations: http://unixwiz.net/techtips/reading-cdecl.html

I'm leaving it here for anyone...
I hope it will be useful to you!

tux4life 2,072 Postaholic

>I had issues with CMD before, so I guess I have the same problem now!
Do you have any suggestions how I can comment the text?

What do you mean by: how can I comment the text?

  • Do you want to write the program's output to a file?
    In that case you might want to run your program from the command line, like this:
    [I]yourprogram[/I] > output.txt (The output of your program will then be written to a file on your harddisk called 'output.txt')
  • Or do you mean that the Command Window pops up, and after entering the information disappears directly?
    (if this is the inconvenience then you might want to add [B]cin.get();[/B] before return 0; if there's one or in case there isn't a return 0; statement just put it on the latest line of your main function...
  • Or do you mean how to add comments to your code?
    In that case you might want to do like this: /* this is a comment */ for C-style comments (these can be spread amongst multiple lines), or // this is also a comment for single line (C++) comments...

>What is important and what's not?
What do you mean? Can you clarify this question?

>I looks like this: "Home team won over guest team with 2-3Press key to continue"
and when you press a key the program shuts down!

Do you want that the "Press …

tux4life 2,072 Postaholic

To begin take a look at this code snippet: http://www.daniweb.com/code/snippet434.html

tux4life 2,072 Postaholic

It would be more correct to say that switch case only works for integer constants :P

To the OP:
Read this before posting!

tux4life 2,072 Postaholic

When home team is 7 and guest team is 3 the CMD shuts down!
Thats my new problem!

= )

There's nothing wrong with your program, with me it just runs fine, this is the output I'm getting:

Title
----------------
Name on home team: MyHomeTeam
How many goals for MyHomeTeam:7

Name of guest team: MyGuestTeam
How many goals for MyGuestTeam:3

MyHomeTeam won home against MyGuestTeam. Final result 7-3

Make the latest line of your main function: [B]cin.get();[/B] and the problem will be solved :)

tux4life 2,072 Postaholic

Thank you for taking your time!
I tried to run it again, but it still doesnt show the right output!

What values are you entering, what output do you get and what's the expected output?

tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

>Can any one help me!?
Yes, where are you having problems with?

BTW, Could you post your own try as well ?

tux4life 2,072 Postaholic

Did you already notice the sticky thread about C++ books at the top of the forum :P ??
However: here's a good one, free and in PDF (it's an ebook) :)

tux4life 2,072 Postaholic

>Salem jumped me about giving away code, so I didn't give an example of the stronger definition. Blame him.
No, giving a stronger definition about the word 'word' is not the same as giving away free code :)

tux4life 2,072 Postaholic

[B]else if (bnr < hnr)[/B] has to be else if (bnr > hnr) :)

Otherwise you've two times the same: if (hnr > bnr) and else if (bnr < hnr) are in my eyes exactly the same, just another way of writing :)

And change else (bnr == hnr); to else if(bnr == hnr) So your fixed code would become:

#include <iostream>
#include <string>


 using namespace std;
  int main(void)
 {

	 string home, guest; 
                 int hnr, bnr;

	 cout << "Title" << endl;
	 cout << "----------------" << endl;

	 cout << "Name on home team: "; cin >> home;
	 cout << "How many goals for " << home << ":";              cin>>hnr;
	 cout << endl;
    
	 cout << "Name of guest team: "; cin >> guest;
	 cout << "How many goals for " << guest << ":"; cin >>     bnr;
	 cout <<endl;
   


	 if (hnr > bnr)
	 {
		  if (hnr > 3 && bnr < 3)
			 cout << "Home team crushed guest  team";
		  else
				cout << home << " won home against " 
				<< guest << ". Final result " 
				 << hnr << "-" << bnr;
		
	 }
	 else if (bnr [B]>[/B] hnr) [B]// changes made here[/B]
	 {	
		  if (bnr > 3 && hnr < 3)
			  cout << "Guest team crushed home team";
		  else
       		  cout << guest << " guest won against " 
			 << home << ". Final result " 
			 << hnr << "-" << bnr;
	 }
	 else [B]if[/B](bnr == hnr) [B]// changes made here[/B]
		 cout << "Tie between " 
			  << …
tux4life 2,072 Postaholic

Excuse me.. I don't understand!
It's the first week for me!
I feel ridiculously stupid! ; )

Never mind, we'll be glad to help you out, just post your current code and we'll take a look :)

tux4life 2,072 Postaholic

Your assignment is to make a program which automatice the output of an sportstitel!
The user inputs the team name and score of the home and guest team. After the program will automaticly write a fitting sentence for the situation.

That part is already implemented, it's working correctly, let's move on to the unimplemented parts:

  • If home team won ridiculously big over guest team <unimplemented>
  • If guest team won ridiculously big over home tam <unimplemented>

:)

tux4life 2,072 Postaholic

>This it the following if-situations I need:
>
>If home team won over guest team <implemented>
>If home team won ridiculously big over guest team <unimplemented>
>If guest team won over home team <implemented>
>If guest team won ridiculously big over home tam <unimplemented>
>If they got the same score <implemented>

Could you define "ridiculously big" ?

tux4life 2,072 Postaholic

No, I need to add more if-situations!
Do you understand what I mean? My english isn't the best!

Yes, I understand what you mean, could you please post your whole assignment, in that way I can better understand the problem you're having :)

tux4life 2,072 Postaholic

The problem was to allow the user to enter a paragraph. I bet there will be more than one line, and to handle multiple lines with getline you need to terminate input with something besides <Enter>.

Hey great programmer, I bet you forgot something :P
Your program doesn't ignore punctuation marks, a great programmer as you would certainly have seen that, not?

e.g.:
Are these: "Hello , World !!!" four words or two ?

tux4life 2,072 Postaholic

Yes, from the beginning, but my teacher wanted me to add more situations!

For example:
"Home team crusched guest with 5-1!"
Vice versa!

Well, that's not so difficult, give it a try (starting from the corrected code), in that case it's easier to track down any future problems :)
You only have to add an extra cout statement ...

tux4life 2,072 Postaholic

You've a strange way to implement such a simple thing:
Change:

if (hnr > bnr)
	 {
		  if (hnr > 3 && bnr < 3)
			 cout << "Home team crushed guest  team";
		  else
				cout << home << " won home against " 
				<< guest << ". Final result " 
				 << hnr << "-" << bnr;
		
	 }
	 else if (bnr < hnr)
	 {	
		  if (bnr > 3 && hnr < 3)
			  cout << "Guest team crushed home team";
		  else
       		  cout << guest << " guest won against " 
			 << home << ". Final result " 
			 << hnr << "-" << bnr;
	 }
	 else (bnr == hnr);
		 cout << "Tie between " 
			  << home << " and " 
			  << guest << ". Final result " 
              << hnr << "-" << bnr; 
  }

To something like this:

if(hnr > bnr) {
        cout << "Home wins!" << endl;
} else if (hnr < bnr) {
        cout << "Guest wins!" << endl;
} else {
        cout << "It's a tie!" << endl;
}

Is that what you intended your code to do?

tux4life 2,072 Postaholic

Settting up gtkmm in Windows:
http://live.gnome.org/gtkmm/MSWindows

Maybe it would be smart to look at the date of the latest post in the thread before you waste your time answering an old thread like this one :(
But I agree with the answer (Finally someone which uses Google) :)