473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

switch not assigning value problem

9
I am trying to get the user to input 1-10 and that will select a a number from an array and place it into a variable. here is the code.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.    do
  4.     {
  5.       cout << "Enter the first row from column 1 to be summed (1-10)";
  6.       cout << endl << endl;
  7.       cin >> answer1;
  8.  
  9.       switch(answer1)
  10.       {
  11.         case '1': a[0][0] = num1;
  12.           break;
  13.         case '2': a[1][0] = num1;
  14.           break;
  15.         case '3': a[2][0] = num1;
  16.           break;
  17.         case '4': a[3][0] = num1;
  18.           break;
  19.         case '5': a[4][0] = num1;
  20.           break;
  21.         case '6': a[5][0] = num1;
  22.           break;
  23.         case '7': a[6][0] = num1;
  24.           break;
  25.         case '8': a[7][0] = num1;
  26.           break;
  27.         case '9': a[8][0] = num1;
  28.           break;
  29.         case '10': a[9][0] = num1;
  30.           break;
  31.         default : cout << "Invalid input, please select a number 1-10"; 
  32.                   cout << endl << endl;
  33.       }//end switch for answer 1
  34.  
  35.       cout << "Enter the second row from column 1 to be summed (1-10)";
  36.       cout << endl << endl;
  37.       cin >> answer2;
  38.  
  39.       switch(answer2)
  40.       {
  41.         case '1': a[0][0] = num2;
  42.           break;
  43.         case '2': a[1][0] = num2;
  44.           break;
  45.         case '3': a[2][0] = num2;
  46.           break;
  47.         case '4': a[3][0] = num2;
  48.           break;
  49.         case '5': a[4][0] = num2;
  50.           break;
  51.         case '6': a[5][0] = num2;
  52.           break;
  53.         case '7': a[6][0] = num2;
  54.           break;
  55.         case '8': a[7][0] = num2;
  56.           break;
  57.         case '9': a[8][0] = num2;
  58.           break;
  59.         case '10': a[9][0] = num2;
  60.           break;
  61.         default : cout << "Invalid input, please select a number 1-10"; 
  62.                   cout << endl << endl;
  63.       }//end switch for answer 2
  64.  
  65.      num1 + num2 = total;
  66.      total = a[j][1];
  67.  
  68.  


the problem is. when I try and add the two numbers (num1 + num2) it says there is a "non-lvalue in assignment".

are my switch statements incorect? can I not do that with an array?

all help is much Appreciated . Thanks in advance.
May 7 '07 #1
2 1549
ilikepython
844 Expert 512MB
I am trying to get the user to input 1-10 and that will select a a number from an array and place it into a variable. here is the code.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.    do
  4.     {
  5.       cout << "Enter the first row from column 1 to be summed (1-10)";
  6.       cout << endl << endl;
  7.       cin >> answer1;
  8.  
  9.       switch(answer1)
  10.       {
  11.         case '1': a[0][0] = num1;
  12.           break;
  13.         case '2': a[1][0] = num1;
  14.           break;
  15.         case '3': a[2][0] = num1;
  16.           break;
  17.         case '4': a[3][0] = num1;
  18.           break;
  19.         case '5': a[4][0] = num1;
  20.           break;
  21.         case '6': a[5][0] = num1;
  22.           break;
  23.         case '7': a[6][0] = num1;
  24.           break;
  25.         case '8': a[7][0] = num1;
  26.           break;
  27.         case '9': a[8][0] = num1;
  28.           break;
  29.         case '10': a[9][0] = num1;
  30.           break;
  31.         default : cout << "Invalid input, please select a number 1-10"; 
  32.                   cout << endl << endl;
  33.       }//end switch for answer 1
  34.  
  35.       cout << "Enter the second row from column 1 to be summed (1-10)";
  36.       cout << endl << endl;
  37.       cin >> answer2;
  38.  
  39.       switch(answer2)
  40.       {
  41.         case '1': a[0][0] = num2;
  42.           break;
  43.         case '2': a[1][0] = num2;
  44.           break;
  45.         case '3': a[2][0] = num2;
  46.           break;
  47.         case '4': a[3][0] = num2;
  48.           break;
  49.         case '5': a[4][0] = num2;
  50.           break;
  51.         case '6': a[5][0] = num2;
  52.           break;
  53.         case '7': a[6][0] = num2;
  54.           break;
  55.         case '8': a[7][0] = num2;
  56.           break;
  57.         case '9': a[8][0] = num2;
  58.           break;
  59.         case '10': a[9][0] = num2;
  60.           break;
  61.         default : cout << "Invalid input, please select a number 1-10"; 
  62.                   cout << endl << endl;
  63.       }//end switch for answer 2
  64.  
  65.      num1 + num2 = total;
  66.      total = a[j][1];
  67.  
  68.  


the problem is. when I try and add the two numbers (num1 + num2) it says there is a "non-lvalue in assignment".

are my switch statements incorect? can I not do that with an array?

all help is much Appreciated . Thanks in advance.
Not sure what you're trying to do. Do you mean "total = num1 + num2;"? Right after you say "total = a[j][1];". Do you mean "a[j][1] = total"? Could please clarify on what you are trying to do?
May 7 '07 #2
svlsr2000
181 Expert 100+
I am trying to get the user to input 1-10 and that will select a a number from an array and place it into a variable. here is the code.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.  
  5. num1 + num2 = total;
  6. total = a[j][1];
  7.  
  8.  


the problem is. when I try and add the two numbers (num1 + num2) it says there is a "non-lvalue in assignment".

are my switch statements incorect? can I not do that with an array?

all help is much Appreciated . Thanks in advance.
num1 + num2 results in rvalue. You cannot assign anything to rvalue. :)
Are you looking for something like
total = num1 + num2;
May 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: sigzero | last post by:
I have a url that ends with ?pid=sqlall. I am using the following to try and get at the "sqlall". I have read many sites to no avail. switch ($_GET) { case 'sqlall': $page->assign('pagetitle',...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
10
by: Chih-Hsu Yen | last post by:
I encountered a strange problem about switch-case statement. switch(cmd) { case 1: statements; break; case 2: statements; break; ... .... case 11: S1; S2; S3; statements;
13
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default:...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
20
by: Ryan Liu | last post by:
Hi, I have a client/server application, using one thread/client approach. I see very high context switch/sec. What are the ways to reduce it? Each thread sleep longer in its endless loop if...
7
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
2
by: narasimp | last post by:
Hi, I have the following code: func1() { unsigned int i; int j = 3; switch(j)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.