Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C
#include<iostream>
using namespace std;
class item
{
    public:
    int itemcode,qty;
    float price;
void input()
{
    cout<<"\n enter item code";
    cin>>itemcode;
    cout<<"\n enter quality";
    cin>>qty;
    cout<<"\n enter price";
    cin>>price;
}
void output
{
    float amount;
    amount=qty*price;
    cout<<"\n total amount="<<amount;
};
};
int main()
{
    item t;
    t.input();
    return 0;
}


What I have tried:

error :variable or field 'output' declared void
Posted
Updated 13-Feb-21 8:20am
v3

Try
void output()
instead of
void output
 
Share this answer
 
Quote:
variable or field 'output' declared void


lets take that literally.

variables/fields can't be void, they always have a type.

methods can be void (i.e. not return anything). Now why could a compiler think something that was intended to be a method isn't a method?

:)
 
Share this answer
 
Comments
[no name] 13-Feb-21 12:53pm    
My tiny 5 for the detailed explanations
Luc Pattyn 13-Feb-21 13:03pm    
Thanks.
I tend to make people think, and hopefully learn...

:)
You forgot the brackets:
void output
{
    float amount;
    amount=qty*price;
    cout<<"\n total amount="<<amount;
};
Should be:
void output()
{
    float amount;
    amount=qty*price;
    cout<<"\n total amount="<<amount;
};
If you double click the error in VS, it will take you straight to the line it found a problem with. For command line compilers, they will list the filename, line and column numbers with the error message, and CTRL+G will take you to a specific line number in most text editors.

But ... do yourself a favour and sort out your indentation - it makes you code a lot easier to read.
 
Share this answer
 
Comments
[no name] 13-Feb-21 12:06pm    
plagarized
CHill60 23-Feb-21 7:23am    
Given that it was posted only 3 minutes after yours I doubt very much it was "plagiarized" or that your solution (or Luc's) even gave OrignalGriff the idea. Much more likely is that it took him much longer to type out his solution, given that he has also included some useful advice on how to find out which line is causing the error
[no name] 23-Feb-21 7:55am    
I'm aware I forgot the smiley. The comment was by no means meant seriously.
Rick York 13-Feb-21 15:29pm    
Those are brackets? I call them parenthesis. These [] are brackets.
OriginalGriff 13-Feb-21 15:50pm    
Nope, those are "square brackets". And these {} are "curly brackets".
Brackets also come in metal, plastic, abs, and wood; but they tend not to compile.

Very versatile things, brackets. :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900