error C2106: '=' : left operand must be l-value
Trying to show the Row totals and the Column totals.
#include <stdio.h>
int main()
{ /* start of main */
#define NUMROWS 5 /* establishes NUMROWS as 5 */
#define NUMCOLS 5 /* establishes NUMCOLS as 5 */
int val[NUMROWS][NUMCOLS] = { {23,06,85,22,01}, /* declares array val to have 5 rows and 5 columns */
{07,33,62,17,04},
{89,71,60,54,33},
{05,21,11,31,12},
{61,25,02,04,69} }; /* initializes array val */
printf("\nRow 0 %d %d %d %d %d", val[0][0], val[0][1], val[0][2], val[0][3], val[0][4]);
printf("\nRow 1 %d %d %d %d %d", val[1][0], val[1][1], val[1][2], val[1][3], val[1][4]);
printf("\nRow 2 %d %d %d %d %d", val[2][0], val[2][1], val[2][2], val[2][3], val[2][4]);
printf("\nRow 3 %d %d %d %d %d", val[3][0], val[3][1], val[3][2], val[3][3], val[3][4]);
printf("\nRow 4 %d %d %d %d %d", val[4][0], val[4][1], val[4][2], val[4][3], val[4][4]);
int sumrow0, sumrow1, sumrow2, sumrow3, sumrow4; /* declares sumrow0, sumrow1, sumrow2, sumrow3, sumrow4 to be a int variable */
sumrow0 = val[0][0] + val[0][1] = val[0][2] + val[0][3] + val[0][4];
sumrow1 = val[1][0] + val[1][1] = val[1][2] + val[1][3] + val[1][4];
sumrow2 = val[2][0] + val[2][1] = val[2][2] + val[2][3] + val[2][4];
sumrow3 = val[3][0] + val[3][1] = val[3][2] + val[3][3] + val[3][4];
sumrow4 = val[4][0] + val[4][1] = val[4][2] + val[4][3] + val[4][4];
int sumcol0, sumcol1, sumcol2, sumcol3, sumcol4; /* declares sumcol0, sumcol1, sumcol2, sumcol3, sumcol4 to be a int variable */
sumcol0 = val[0][0] + val[1][0] = val[2][0] + val[3][0] + val[4][0];
sumcol1 = val[0][1] + val[1][1] = val[2][1] + val[3][1] + val[4][1];
sumcol2 = val[0][2] + val[1][2] = val[2][2] + val[3][2] + val[4][2];
sumcol3 = val[0][3] + val[1][3] = val[2][3] + val[3][3] + val[4][3];
sumcol4 = val[0][4] + val[1][4] = val[2][4] + val[3][4] + val[4][4];
#define ROWTOTALS 5 /* establishes ROWTOTALS containing 5 numbers */
int row[ROWTOTALS] = { sumrow0, sumrow1, sumrow2, sumrow3, sumrow4 };
#define COLTOTALS 5 /* establishes COLTOTALS containing 5 numbers */
int col[COLTOTALS] = { sumcol0, sumcol1, sumcol2, sumcol3, sumcol4 };
printf("\nRow totals: %d", row);
printf("\nColumn totals: %d", col);
return 0;
}
I receive this message after building:
1>------ Build started: Project: WA 4 A 1 Christopher Caron, Configuration: Debug Win32 ------
1> WA 4 A 1 Christopher Caron.cpp
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(21): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(22): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(23): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(24): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(25): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(28): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(29): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(30): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(31): error C2106: '=' : left operand must be l-value
1>c:\users\chris\documents\visual studio 2010\projects\wa 4 christopher caron\wa 4 christopher caron\wa 4 a 1 christopher caron.cpp(32): error C2106: '=' : left operand must be l-value
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any thoughts?
Re: error C2106: '=' : left operand must be l-value
Quote:
Originally Posted by
dedite
Code:
int sumrow0, sumrow1, sumrow2, sumrow3, sumrow4; /* declares sumrow0, sumrow1, sumrow2, sumrow3, sumrow4 to be a int variable */
sumrow0 = val[0][0] + val[0][1] = val[0][2] + val[0][3] + val[0][4];
And what are you going to achieve with this strange assignment? :confused:
Re: error C2106: '=' : left operand must be l-value
Please format your code before posting and use code tags (Go Advanced, select code, click '#').
In addition to post #2, you will also have problems with
Code:
printf("\nRow totals: %d", row);
printf("\nColumn totals: %d", col);
as row and code are of type int* If you want to display the individual row and col totals you'll have to display for each one.
You are also making heavy weather of doing this by hardcoding the sums. What happens if the number of cols or rows changes? It would be best to use for loops.
As this looks like being an assignment, I can't give you the revised code as that would be cheating but once you get it to compile and try using for loops and re-post your code we'll be happy to comment.