Error when compiling

leflon, are yaw there?
Below is my simple program.  I'm new and learing c++.  I can't find my error in this.  When I try to compile it, I receive this error:
: error C2239: unexpected token '{' following declaration of 'main'
Error executing cl.exe.
Any suggestions?


int main
{
  int Pennies = 0;
  int OrgPennies = 0;  // for storing the original amount of pennies.

  // This program will calculate any amount of Pennies into: $100's, $50's, $20's, $10's , $5's, 1's, Quarters, Dimes, Nickles and the remaining pennies.
  cin >> Pennies;
  // Possible error handling.
  OrgPennies = Pennies;

  // Splitting up the money
  int Bill100 = Pennies/10000;
  Pennies = Pennies%10000;

  int Bill50 = Pennies/5000;
  Pennies = Pennies%5000;

  int Bill20 = Pennies/2000;
  Pennies = Pennies%2000;

  int Bill10 = Pennies/1000;
  Pennies = Pennies%1000;

  int Bill5 = Pennies/500;
  Pennies = Pennies%1000;

  int Bill1 = Pennies/100;
  Pennies = Pennies%100;

  int Coin25 = Pennies/25;
  Pennies = Pennies%25;

  int Coin10 = Pennies/10;
  Pennies = Pennies%10;

  int Coin5 = Pennies/5;
  Pennies = Pennies%5;

  int Coin1 = Pennies/1;
  Pennies = Pennies%1;

  cout << "For " << OrgPennies << " You will get:" << endl;

  cout << Bill100 << "One Hundred dollar bills" << endl;

  cout << Bill50 << "Fifty dollar bills" << endl;

  cout << Bill20 << "Twenty dollar bills" << endl;

  cout << Bill10 << "Ten dollar bills" << endl;

  cout << Bill5 << "Five dollar bills" << endl;

  cout << Bill1 << "One dollar bills" << endl;

  cout << Coin25 << "Quarters" << endl;

  cout << Coin10 << "Dimes" << endl;

  cout << Coin5 << "Nickels" << endl;

  cout << Coin1 << "Pennies" << endl;

  cout << Pennies << "pennies" << endl;

  return 0;  // program end
}
super_man_1976Asked:
Who is Participating?
 
leflonConnect With a Mentor Commented:
Hi super_man_1976,

yes exactly that way, but don't forget the using namespace std;

#include <iostream>
using namespace std;
int main/int argc, char* argv[])
{
...// your prog (with the return 0; at the end
}

leflon
0
 
Sys_ProgConnect With a Mentor Commented:
() is missing after main
it should be
int main ()

amit
0
 
grg99Connect With a Mentor Commented:
main is passed two arguments, so should be declared as "int main( int argc, char * argv[] )"



0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Sys_ProgCommented:
>>  main is passed two arguments, so should be declared as "int main( int argc, char * argv[] )"

Where are the two arguments required in his code..........This is required only if u plan to process/use command line parameters

Amit
0
 
super_man_1976Author Commented:
I just tryied both of those sugestions and unfortuinally I still get errors
If I try just the int main () I get 15 error(s), 1 warning(s) Most of the errors said "illegal, right operand has type 'char"
when I tried "int main( int argc, char * argv[] )" I get the same errors as below:

error C2065: 'cin' : undeclared identifier
warning C4552: '>>' : operator has no effect; expected operator with side-effect
(42) : error C2065: 'cout' : undeclared identifier
(42) : error C2297: '<<' : illegal, right operand has type 'char [5]'
(42) : error C2065: 'endl' : undeclared identifier
(44) : error C2297: '<<' : illegal, right operand has type 'char [25]'
(46) : error C2297: '<<' : illegal, right operand has type 'char [19]'
(48) : error C2297: '<<' : illegal, right operand has type 'char [20]'
(50) : error C2297: '<<' : illegal, right operand has type 'char [17]'
(52) : error C2297: '<<' : illegal, right operand has type 'char [18]'
(54) : error C2297: '<<' : illegal, right operand has type 'char [17]'
(56) : error C2297: '<<' : illegal, right operand has type 'char [9]'
(58) : error C2297: '<<' : illegal, right operand has type 'char [6]'
(60) : error C2297: '<<' : illegal, right operand has type 'char [8]'
(62) : error C2297: '<<' : illegal, right operand has type 'char [8]'
(64) : error C2297: '<<' : illegal, right operand has type 'char [8]'
Error executing cl.exe.

15 error(s), 1 warning(s)
0
 
Sys_ProgCommented:
Inlcude

#include <iostream> in your program

Also,
EITHER include the foloowing statement at top after includes
using namespace std;
OR
replace cout and cin with std::cout and std::cin respectively

Amit
0
 
super_man_1976Author Commented:
Where does that go? At the very top like this?

#include <iostream>
int main ()

0
 
Sys_ProgCommented:
Your code should be

#include <iostream>

using namespace std ;

int main () {
      // Your code
}


Amit
0
 
leflonCommented:
super_man_1976,

oops, typo must be
int main(int argc, char* argv[])

1.) if you use a function or object (datatype, etc.) in C++ you have to eventually (mainly most of the times) include a so called header file at the beginnig of the cpp file you use the function in.
as you use cout here you have to include the proper file iostream (the <> tells the compiler to search for this file in the specified input-file dirs).

2.) the vars argc and argv after main tell you the number (argc) and the text (argv, array of strings) of the parameters you pass to the prog on the command line.
so a call of:
  prog.exe first second third
will give you
  argc = 4
  argv[0] = prog.exe
  argv[1] = first
  argv[2] = second
  argv[3] = third

as you are new to c++ let me ask you:
do you already have a book which helps you on your way to learning and understanding the language?
if not we sure can make a few helpful recommandations. :-)

cheers
leflon
0
 
leflonCommented:
super_man_1976,

"Thinking in C++" is a good (and free) book, especially for people you want to learn the language, you may want to take a look at

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

leflon
0
 
super_man_1976Author Commented:
Thanks a whole bunch leflon for all the help the last few days.  I'll be working on my prog tonight and try what you recommended.  The only book I have is Sam's Teach your self C++ in 21 days, but I haven't really done a whole lot with it yet.  Thanks for the link above, I'll check it out.  There are so many books to choose from.  Anyway, I'll post back tonight.

0
 
leflonCommented:
no prob, glad i can be of any help!
take your time (to read one or two of the many books) and dont't hesitate to ask if you need further help.
and you better reward the other guys who helped you in this thread, so they come back and do so again ;)

leflon
0
 
super_man_1976Author Commented:
Thanks for the EE advice, as I'm new to it.  This has got to be the best darn resource for informatin that I've ever been to!  
Be back soon.
0
 
super_man_1976Author Commented:
leflon,
My program actually works!  There is just one more thing I'm struggling with.  When I first execute the program it just has the blinking curser.  I want to have the question displayed "How many pennies do you have?”  I can't seem to get it right.  Below is the up to date code for my simple prog.  Man, this is has been a great learning experience!  By the way that book look nice, thanks.


#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
  int Pennies = 0;
  int OrgPennies = 0;  // For storing the original amount of pennies.

  /* This program will calculate any amount of Pennies into:
                                                                                          $100's
                                                                                          $50's
                                                                                          $20's
                                                                                          $10's
                                                                                          $5's
                                                                                          $1's
                                                                                          Quarters
                                                                                          Dimes
                                                                                          Nickles
                                                                                          Remaining pennies */
  cin >> Pennies;
  // Possible error handling.
  OrgPennies = Pennies;

  // Splitting up the money
  int Bill100 = Pennies/10000;
  Pennies = Pennies%10000;

  int Bill50 = Pennies/5000;
  Pennies = Pennies%5000;

  int Bill20 = Pennies/2000;
  Pennies = Pennies%2000;

  int Bill10 = Pennies/1000;
  Pennies = Pennies%1000;

  int Bill5 = Pennies/500;
  Pennies = Pennies%1000;

  int Bill1 = Pennies/100;
  Pennies = Pennies%100;

  int Coin25 = Pennies/25;
  Pennies = Pennies%25;

  int Coin10 = Pennies/10;
  Pennies = Pennies%10;

  int Coin5 = Pennies/5;
  Pennies = Pennies%5;

  int Coin1 = Pennies/1;
  Pennies = Pennies%1;

  cout << "For " << OrgPennies << " pennies you will receive:" << endl;

  cout << Bill100 << " One Hundred dollar bills " << endl;

  cout << Bill50 << " Fifty dollar bills " << endl;

  cout << Bill20 << " Twenty dollar bills " << endl;

  cout << Bill10 << " Ten dollar bills " << endl;

  cout << Bill5 << " Five dollar bills " << endl;

  cout << Bill1 << " One dollar bills " << endl;

  cout << Coin25 << " Quarters " << endl;

  cout << Coin10 << " Dimes " << endl;

  cout << Coin5 << " Nickels " << endl;

  cout << Coin1 << " Pennies " << endl;

  return 0;  // program end
}
0
 
leflonCommented:
hi

just take a look at one of your earlier questions. you hab this initial output (describing the use of your prog) in one of your posts there.
ckeck:
http:Q_20955223.html#10845828

just enter the same two cout statements in front of your cin >> Pennies, line

leflon
0
 
super_man_1976Author Commented:
O yeah, that make obvious sense.  Thanks again teach!


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.