Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > hi problem, with c++ code i am learn so plz tell me what i did worng and how fix

Reply
Thread Tools

hi problem, with c++ code i am learn so plz tell me what i did worng and how fix

 
 
fastwings
Guest
Posts: n/a
 
      04-17-2004
mm the code
//////makemenu.h////
class menu {

public:
int op;
pmenu(int op,int sub = 0)
{
switch op
{
case 1:
show(op,0);
break;
case 2:
show(op,0);
break;
case 3:
show(op,0);
break;
case 4:
show(op,0);
break;
default:
msgerr(01);
}
}
show (int op,int sub=0)
{
cont<<"ok"<<end1<<"u press : "<<op;
}
};
/////////menus.cpp//////
#ifndef __file__
#define __file__ "telcom.db"
#endif
#include <iostream.h>
#include <stdio.h>
#include <fstream.h>
#include "makemenu.h"
main {
menu p1;
char option;
int total=3,stot=9,op;
showstars(total,stot);
cont<<"Enter number 1-4"<<end1;
option = getchar();
p1.pmenu(option,0);
return(0);
}
showstars(int line,int chrs)
{
int i;
for (i=1;i<=line;i++)
{
if (i != 1)
{
cont<<end1<<setfill("*")<<setw(chrs);
}
else
{
cont<<setfill("*")<<setw(chrs);
}
}
cont<<end1;
return(1);
}
the errors:
--------------------Configuration: tt - Win32
Debug--------------------
Compiling...
menus.cpp
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(24)
: warning C4183: 'pmenu': member function definition looks like a
ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(2
: warning C4183: 'show': member function definition looks like a ctor,
but name does not match enclosing class
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h( :
error C2061: syntax error : identifier 'op'
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h( :
error C2143: syntax error : missing ';' before '{'
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(9) :
error C2046: illegal case
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(11)
: error C2043: illegal break
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(12)
: error C2046: illegal case
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(14)
: error C2043: illegal break
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(15)
: error C2046: illegal case
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(17)
: error C2043: illegal break
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(1
: error C2046: illegal case
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(20)
: error C2043: illegal break
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(21)
: error C2047: illegal default
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(22)
: error C2065: 'msgerr' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(27)
: error C2065: 'cont' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(27)
: error C2297: '<<' : illegal, right operand has type 'char [3]'
c:\program files\microsoft visual studio\myprojects\tt\makemenu.h(27)
: error C2065: 'end1' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp( :
error C2501: 'main' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp( :
error C2239: unexpected token '{' following declaration of 'main'
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp(25) :
error C2065: 'setfill' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp(25) :
error C2065: 'setw' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp(25) :
warning C4552: '<<' : operator has no effect; expected operator with
side-effect
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp(29) :
warning C4552: '<<' : operator has no effect; expected operator with
side-effect
c:\program files\microsoft visual studio\myprojects\tt\menus.cpp(32) :
warning C4552: '<<' : operator has no effect; expected operator with
side-effect
Error executing cl.exe.

menus.obj - 19 error(s), 5 warning(s)
===========================================
plz tell me how i can fix and know not to do next time i try but....
 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      04-17-2004
On 17 Apr 2004 13:44:38 -0700 in comp.lang.c++, http://www.velocityreviews.com/forums/(E-Mail Removed)
(fastwings) wrote,
>public:
> int op;
> pmenu(int op,int sub = 0)
> {


You forgot to declare the return type of function pmenu.

 
Reply With Quote
 
 
 
 
osmium
Guest
Posts: n/a
 
      04-17-2004
fastwings writes:

> mm the code
> //////makemenu.h////
> class menu {
>
> public:
> int op;
> pmenu(int op,int sub = 0)
> {
> switch op
> {
> case 1:
> show(op,0);
> break;
> case 2:
> show(op,0);
> break;
> case 3:
> show(op,0);
> break;
> case 4:
> show(op,0);
> break;
> default:
> msgerr(01);
> }
> }
> show (int op,int sub=0)
> {
> cont<<"ok"<<end1<<"u press : "<<op;


cout?

> }
> };
> /////////menus.cpp//////
> #ifndef __file__
> #define __file__ "telcom.db"
> #endif
> #include <iostream.h>
> #include <stdio.h>
> #include <fstream.h>
> #include "makemenu.h"
> main {
> menu p1;
> char option;
> int total=3,stot=9,op;
> showstars(total,stot);
> cont<<"Enter number 1-4"<<end1;


cout?? endl as in 'ell'

> option = getchar();
> p1.pmenu(option,0);
> return(0);
> }
> showstars(int line,int chrs)
> {
> int i;
> for (i=1;i<=line;i++)
> {
> if (i != 1)
> {
> cont<<end1<<setfill("*")<<setw(chrs);
> }
> else
> {
> cont<<setfill("*")<<setw(chrs);
> }
> }
> cont<<end1;
> return(1);
> }


I suppose there is a lot more too.


 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      04-17-2004
fastwings wrote:

> mm the code
> //////makemenu.h////
> class menu {
>
> public:
> int op;
> pmenu(int op,int sub = 0)


Your function is missing a return type. Every function needs a return
type. If you don't want to return anything, use void. You should also
consider implementing your function not in the header, but a
separate .cpp file.

> {
> switch op


switch (op)

> {
> case 1:
> show(op,0);
> break;
> case 2:
> show(op,0);
> break;
> case 3:
> show(op,0);
> break;
> case 4:
> show(op,0);
> break;
> default:
> msgerr(01);


Where is the function msgerr?

> }
> }
> show (int op,int sub=0)


Again, return type missing.

> {
> cont<<"ok"<<end1<<"u press : "<<op;


'cont' is supposed to be 'cout' and the 'end1' should be 'endl'. Also,
you forgot to #include the header needed for them. So you need to add:

#include <iostream>

at the top. Also, it would be std::cout and std::endl.

> }
> };
> /////////menus.cpp//////
> #ifndef __file__
> #define __file__ "telcom.db"
> #endif


The above three lines look like they are supposed to be an include
guard, but are used wrong. First, they need to be in the header, not
the implementation file. Further, the #endif needs to be at the bottom
of the file, so that the #ifndef/#endif encloses the whole file.


> #include <iostream.h>


#include <iostream>

The version with .h was never part of standard C++ and is outdated for
years and deprecated in some compilers.

> #include <stdio.h>
> #include <fstream.h>


#include <fstream>

> #include "makemenu.h"
> main {


Again, your function is missing a return type. For main that must be
int.

> menu p1;
> char option;
> int total=3,stot=9,op;
> showstars(total,stot);


showstars is not yet dechared here, so the compiler doesn't know it yet.
Either put the definition of that function before main, or add a
prototype before it.

> cont<<"Enter number 1-4"<<end1;


Again, replace cont with std::cout and end1 with std::endl.

> option = getchar();
> p1.pmenu(option,0);
> return(0);
> }
> showstars(int line,int chrs)


Return type missing again.

> {
> int i;
> for (i=1;i<=line;i++)
> {
> if (i != 1)
> {
> cont<<end1<<setfill("*")<<setw(chrs);
> }
> else
> {
> cont<<setfill("*")<<setw(chrs);
> }
> }
> cont<<end1;
> return(1);
> }


The rest shold be clear now.

> plz tell me how i can fix and know not to do next time i try but....


Have you actually had a look at the program and the error messages
yourself? Some of the errors should be obvious, even for a beginner.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
There is some prolem in the funciton modification below. Please checkit and tell me what is worng? Unpopular C++ 2 02-15-2008 08:41 AM
Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee Java 22 03-21-2006 07:02 AM
Re: plz help!!! plz plz plz plzplzplz help the noob alkzy Microsoft Certification 0 10-31-2004 10:04 PM
Computer Problems... Plz Plz Plz HELP ME..... Nick Computer Support 0 06-04-2004 08:50 PM



Advertisments