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

Lanie Molinar laniemolinar91 at gmail.com
Sat Nov 4 10:16:07 UTC 2017


I’m resending this since it didn’t go to both lists last time. I fixed the issue with my loop and got it working, but now I seem to be having a rounding error in test 2 of the testbed. I tried using floats with cout.setf(ios::fixed), and cout.precision(2), but they only fixed part of the problem I was having. I’m not sure what else I can do to fix this.

Sent from Mail for Windows 10

From: Dzhovani Chemishanov
Sent: Friday, November 3, 2017 2:46 PM
To: program-l at freelists.org
Cc: Lanie Molinar via nfbcs
Subject: [program-l] Re: [nfbcs] Re: Help with Another Assignment

Mike is quite right. A good thing is to open random online tutorial
and read carefully what any of them have to say about loops because
the theoretical stuff really matters.

On 11/3/17, Mike Gorse <mike at straddlethebox.org> wrote:
> I'm intentionally being a little vague and trying to help you find the
> problem with your code, rather than feeding a solution to you, since
> debugging is an important part of programming and, thus, part of what you
> need to be learning, and that might mean inspecting your code, or
> temporarily inserting statements to print things, or using a debugger, or
> some combination. Anyhow, you have
> while (i < num)
> so your loop will execute until i == num
>
> If there is a case where i does not change and neither does num and
> nothing happens that will cause them to change in any future iteration,
> then the loop will continue to execute forever, and you'll need to
> terminate your program.
>
> On Fri, 3 Nov 2017, Lanie Molinar wrote:
>
>>
>> I have no idea how to fix this one. Any suggestions?
>>
>>
>>
>> Sent from Mail for Windows 10
>>
>>
>>
>> From: Mike Gorse
>> Sent: Friday, November 3, 2017 10:48 AM
>> To: Lanie Molinar via nfbcs
>> Cc: Lanie Molinar; program-l at freelists.org
>> Subject: Re: [nfbcs] [program-l] Re: Help with Another Assignment
>>
>>
>>
>> I wouldn't say that you're getting a blank line, so much as that your
>>
>> program is locking up. Looking at your while loop in averageGrades(), it
>>
>> isn't going to terminate in some cases.
>>
>>
>>
>> On Fri, 3 Nov 2017, Lanie Molinar via nfbcs wrote:
>>
>>
>>
>> > I fixed it and got it to stop giving me errors, but I’m now having
>> > another issue. For the condition that’s supposed to cout dashes, I get
>> > only a blank line after I enter -1 for all 10 grades.
>>
>> >
>>
>> > Sent from Mail for Windows 10
>>
>> >
>>
>> > From: Dzhovani Chemishanov
>>
>> > Sent: Friday, November 3, 2017 9:22 AM
>>
>> > To: Lanie Molinar
>>
>> > Cc: program-l at freelists.org; Lanie Molinar via nfbcs
>>
>> > Subject: Re: [program-l] Re: [nfbcs] Help with Another Assignment
>>
>> >
>>
>> > Hi,
>>
>> >  As I said, my c++ is rusty but still I'd be quite surprised to find
>>
>> > working code of the type:
>>
>> > cout << some_text << a_void_function();
>>
>> > It is okay to have a cout statement in a void function, but it is not
>>
>> > okay to have a void function in a cout statement.
>>
>> > Any other type of function that returns printable result could be
>>
>> > called from a cout, but the fundamental property of void functions is
>>
>> > that they do not return value to be sent to the c out stream.
>>
>> >  Can you check your previous project and compare the approach there
>>
>> > with the current one?
>>
>> >
>>
>> > On 11/3/17, Lanie Molinar <laniemolinar91 at gmail.com> wrote:
>>
>> >> 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
>>
>> >>>
>>
>> >>
>>
>> >>
>>
>> >
>>
>> >
>>
>>
>>
>>
>>
> ---311908982-1185058725-1509726280=: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
>
** 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: putty.log
Type: application/octet-stream
Size: 31471 bytes
Desc: not available
URL: <http://nfbnet.org/pipermail/nfbcs_nfbnet.org/attachments/20171104/288dc0f0/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a31.cpp
Type: application/octet-stream
Size: 2379 bytes
Desc: not available
URL: <http://nfbnet.org/pipermail/nfbcs_nfbnet.org/attachments/20171104/288dc0f0/attachment-0001.obj>


More information about the NFBCS mailing list