You are here:

C++/mathematical operations on a table in a for loop


I have this code:

(book_table[row].volume - order) = book_table[row].volume;
(book_table[row].price * order) = order_total;

where book_table is in BOOK_STRUCT and all variables are declared.
It is not in a loop and is designed to change the volume amount in the table, and calculate the price of the order.
It is telling me: non-Ivalue in assignment.

How do I get these variables to read from the table and reaccess the table to change the numbers?
This code is in a function.

Also, I am trying to write the same table structure into a file. I am getting garbage in the file when I try to output using:

    cin.getline(file_name, 81);
    ofstream out_file(file_name);

    for (row = 0; row < size; ++row)
    out_file << book_table;

book_table[] is my table name within the structure.
PLEASE PLEASE help me I have been working on this for hours and I know it is probably an easy fix.

Thank you so, so much.


First of all, regarding your first line of the code:

(book_table[row].volume - order) = ...

The expression on the left side is not variable, so you cannot assign something to the result of the computation.  You should give a variable there, for example:

book_table[row].volume = book_table[row].volume - order;

Regarding writing to the file.  Your code will work ONLY if you've got operator<< defined for the type of "book_table" variable. So you eather can define operator<< for BOOK_STRUCT or you can pass value-value over "book_table" and print each value to a file.



All Answers

Answers by Expert:

Ask Experts


Evgeny Popovich


I can answer C questions related to the language itself, OOP/OOD questions, C performance optimizations questions, 3D simulators questions, file-systems development questions.


I've got an experience of 4 years developing in C , from which 3 years developing real-time 3D simulations, and 1 years of system development. I've got extensive experience with OOP/OOD and a bit freak of clean code and good programming style and practices.


1. I/ITSEC 2005 Proceedings: Developing a Low Intensity Conflict Urban Simulation: Lessons Learned. 2. TESI 2005 Proceedings: Simulating an Infantry Platoon with Human-in-the-Loop.

I've got my B.Sc. in Software Engineering from the Technion - Israel Institute of Technology.

©2017 All rights reserved.