[nfbcs] [program-l] Re: Help with Another Assignment

Lanie Molinar laniemolinar91 at gmail.com
Fri Nov 3 13:50:08 UTC 2017


Hi. I’ve used cout statements this way in a void function before, though, so I don’t understand why it doesn’t work. In a project I did just a couple weeks ago, I created a display function that was void but had multiple cout statements in it. This seems like the same kind of thing.

Sent from Mail for Windows 10

From: Dzhovani Chemishanov
Sent: Friday, November 3, 2017 8:26 AM
To: program-l at freelists.org
Cc: Lanie Molinar via nfbcs; laniemolinar91 at gmail.com
Subject: Re: [program-l] Re: [nfbcs] Help with Another Assignment

this line
cout << "Average Grade: " << averageGrades(grades, NUMGRADES) << "%\n";
the function that you are calling is void and you can't print result
from it because it doesn't return anything.
move all cout statements in it and avoid all the mess.
Also, my cpp is rusty, so I hope that the way you are trying to fill
in the array is valid.
HTH,
Dzhovani

On 11/3/17, Mike Gorse <mike at straddlethebox.org> wrote:
> Hi Lanie,
>
> If I try to compile your code, then I get this error:
>
> a31.cpp:71:30: error: no match for ‘operator<<’ (operand types are
> ‘std::basic_ostream<char>’ and ‘void’)
>      cout << "Average Grade: " << averageGrades(grades, NUMGRADES) <<
> "%\n";
>
> The "void" is the key here--the compiler thinks that you are trying to
> pass something with a void type to the stream. From that, I'd guess that
> averageGrades() isn't returning a value. When I look at the function
> prototype, it is, in fact, returning void, rather than returning a value
> that can be printed by the caller.
>
> Hth,
> -Mike
> ---311908982-671148510-1509712654=:14384--
> ** To leave the list, click on the immediately-following link:-
> ** [mailto:program-l-request at freelists.org?subject=unsubscribe]
> ** If this link doesn't work then send a message to:
> ** program-l-request at freelists.org
> ** and in the Subject line type
> ** unsubscribe
> ** For other list commands such as vacation mode, click on the
> ** immediately-following link:-
> ** [mailto:program-l-request at freelists.org?subject=faq]
> ** or send a message, to
> ** program-l-request at freelists.org with the Subject:- faq
>




More information about the NFBCS mailing list