• Welcome to Valhalla Legends Archive.
 

problem with simple prog

Started by Hamtaro, February 13, 2004, 04:07 PM

Previous topic - Next topic

Hamtaro

this is the code im using:

#include <iostream>
int main()
{
using namespace std;
int number1 = 22;
if (number1 == 22) cout << "number1 is equal to 22";
return=0;
}


and its saying "parse error before `='  " on line 7 (return=0;)
i cant figure out what it means.. any help?  sry to bug u with such simple code but i cant figure this out ^^;.. im using the Dev-C++ compiler could that be the problem?

Kp

Why're you assigning zero to a reserved keyword?  Also, there's no need to use that if test -- you're guaranteeing that the number will be 22.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Hamtaro

lol.. thanx

its supposed to be

return 0;

didnt mean for it to be a variable.  im just trying to get this to work bcuz when i execute the progs it closes it as soon as it finishes and i havnt gone deep enough to make it ask me to push a button to end it so im using the "cin" to delay it.  then i wanted to turn the cin's input into a variable and output that variable and it wouldnt work so i went back to the even more basic basics.  if u dont understand thats ok ^^;

Kp

Quote from: Hamtaro on February 13, 2004, 04:28 PMdidnt mean for it to be a variable.  im just trying to get this to work bcuz when i execute the progs it closes it as soon as it finishes and i havnt gone deep enough to make it ask me to push a button to end it so im using the "cin" to delay it.  then i wanted to turn the cin's input into a variable and output that variable and it wouldnt work so i went back to the even more basic basics.  if u dont understand thats ok ^^;

It would help greatly if you actually put some effort into being understandable.  It has been my experience that program consoles don't go away if you actually run the program from a console like you're supposed to.  Perhaps you were doing something foolish like double clicking it in Explorer to run it?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Hamtaro

#4
QuoteIt would help greatly if you actually put some effort into being understandable.  It has been my experience that program consoles don't go away if you actually run the program from a console like you're supposed to.  Perhaps you were doing something foolish like double clicking it in Explorer to run it?
i dont understand?
i think u mean running it from the cmd prompt?  ya it doesnt when i do that but if theres a button to run it in the compiler itself.. why not use that?  i see what you mean now ^^;

MoNksBaNe_Agahnim

Quote from: Hamtaro on February 13, 2004, 04:07 PM
this is the code im using:

#include <iostream>
int main()
{
using namespace std;
int number1 = 22;
if (number1 == 22) cout << "number1 is equal to 22";
return=0;
}


shouldn't you declare namespaces outside of functions, like you would #include files and global variables? Haven't had much practice with namespaces but every example I have seen has them declared as...


#include <iostream.h>

using namespace std;

int main()
{
}

Kp

Quote from: Hamtaro on February 13, 2004, 04:39 PMif theres a button to run it in the compiler itself.. why not use that?

because it closes when the program exits, as you told us in your prior post?   Seems pretty obvious that if doing it that way causes a problem reading the output before it vanishes, you shouldn't do it that way!
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Hamtaro

ya.. ive been looking since u said that for a button to just plain compile it bcuz its just compiling/running in memory and not saving the exe anywhere that i can tell..

about using namespaces.. i dont know =|  this book is preaching that if u dont need to use it (in this case, namespaces) outside of one function, then you shouldnt declare it globally.

i think i said that right :)

Kp

Quote from: Hamtaro on February 13, 2004, 05:28 PM
ya.. ive been looking since u said that for a button to just plain compile it bcuz its just compiling/running in memory and not saving the exe anywhere that i can tell..

It takes some pretty fancy code work to run a full executable without ever writing it to disk (it's much easier to do with DLLs).  I suspect you're just unable to find the save directory.  Check where you told the compiler to save it?  I prefer using makefiles, so I don't use dev-C++.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Hamtaro

no~ it saves it in .cpp as c++ source <-- may be a common thing i dont know..  and i found out that if you have an error and try to compile it, it erases the exe for some reason.. =\ oh well i have borland too but its really old and u have to put .h after include files in it and u dont in dev so thats why i chose it in the beginning =P (i figured out later about the .h)

Dyndrilliac

If you want to make the program pause and wait for a keystroke before moving on to the next statement, do this:

#include <iostream.h>
#include <conio.h>

int main
{

int x;
int y;

cout<<"Your text here, b;ah blah blah"<<endl;

getch(); // pauses and waits for a keystroke before movin on

return 0;
}
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

iago

The easiest (but, as Skywing will say, not the best) way to do it is:

#include <stdlib.h>

....

  system("pause");
  return 0;
}
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Skywing

Quote from: iago on February 14, 2004, 11:35 AM
The easiest (but, as Skywing will say, not the best) way to do it is:

#include <stdlib.h>

....

  system("pause");
  return 0;
}
Easiest? getch() is less typing!

Dyndrilliac

Don't getch() and pause do the same effect?
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Hamtaro

#14
thx ^^
how do i take whats inputted and turn it into a variable?

is it:

#include <iostream.h>
#include <string.h>

int main()
}
 using namespace std;
 string text;
 cin << text;
 return 0;
}

i may have to include another file let me see..
yep.. <string>

also in this:
#include <iostream>
int main()
{
using namespace std;
int number1 = 22;
cout << boolalpha << (number1 == 22);
return 0;
}


its exactly like the book says and its saying i need to declare boolalpha but the book doesnt.  its supposed to give me either "false" or "true"