472,978 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Error invalid operands of types 'void' and 'int'...

I making a simple single number scrambler/encryptor and as I tried to build the console application the following error
occurred:

error: invalid operands of types 'void' and 'int' to binary 'operator%'

I have no idea what this means. The source code is bellow.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int nTimer;
  10.     int nInput;
  11.     int nRand;
  12.     int nInRa;
  13.  
  14.     nTimer = 0;
  15.     nRand = 1;
  16.     nInRa = 0;
  17.  
  18.     cout << "Input a number" << endl;
  19.     cin >> nInput;
  20.  
  21.     while(nTimer < 5){
  22.         nInRa = srand(nRand)% 3 + 1;//error is on this line
  23.  
  24.         if(nInRa == 1){
  25.             nInput = nInput + 1;
  26.         }
  27.         if(nInRa == 2){
  28.             nInput = nInput + 2;
  29.         }
  30.         if(nInRa == 3){
  31.             nInput = nInput + 3;
  32.         }
  33.         nTimer = nTimer + 1;
  34.         nRand = nRand + 1;
  35.  
  36.  
  37.     }
  38.     cout << nInput;
  39.     return 0;
  40. }
  41.  
I am running code::blocks as my IDE on Ubuntu.
Thank you for any help!
Oct 22 '14 #1

✓ answered by divideby0

srand doesn't return a value, but you're trying to assign it as though it did to nInRa. srand is your seed, which generally takes time(NULL) as its argument... include time.h or ctime

you'd want rand to generate the "random" sequence.

Expand|Select|Wrap|Line Numbers
  1. srand((unsigned)time(NULL));
  2.  
  3. nInRa = rand() % 3 + 1;
  4.  

2 13569
divideby0
131 128KB
srand doesn't return a value, but you're trying to assign it as though it did to nInRa. srand is your seed, which generally takes time(NULL) as its argument... include time.h or ctime

you'd want rand to generate the "random" sequence.

Expand|Select|Wrap|Line Numbers
  1. srand((unsigned)time(NULL));
  2.  
  3. nInRa = rand() % 3 + 1;
  4.  
Oct 22 '14 #2
Thank you so much I heard you could use time.h but I didnt know how!
Oct 22 '14 #3

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

Similar topics

6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
7
by: bazley | last post by:
I've been tearing my hair out over this: #ifndef MATRIX2_H #define MATRIX2_H #include <QVector> template<class T> class Matrix2 { public:
4
by: muthu | last post by:
In the following code it gives the error "error: invalid operands to binary &" Why it is happening #include <signal.h> #include <errno.h> #define SIGBAD(signo) ((signo) <= 0 || (signo) >=...
2
by: tkirankumar | last post by:
Hi all, uname -a SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M g++ -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs Configured with:...
11
by: Spiros Bousbouras | last post by:
#include <stdlib.h> int main(void) { char **p1 ; const char **p2 ; p1 = malloc(5 * sizeof(char *)) ; if (p1 == 0) return EXIT_FAILURE ; p2 = p1 + 1 ; p2 - p1 ;
2
by: xelloss | last post by:
#include<cstdlib> #include<iostream> #include<iomanip> #include<vector> #include<fstream> using namespace std; double sum(vector<double> x) { double total = 0.0;
5
by: Sheldon | last post by:
Hi Everyone, I have defined a function: struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct Transient retv); and in the code: struct Transient arrFromHdfNode(HL_NodeList...
2
by: Genro | last post by:
#include<stdio.h> #include<TX/graphics.h> #include<time.h> // I need help! struct Krug{ double _x; double _y; double _skox; double _skoy; double...
2
by: Tyler Palmer | last post by:
I am having a problem with my program. I cant figure out a solution for the compiler error im getting. In function `double endingConversion(double)': invalid operands of types `double...
15
by: categami | last post by:
hey i need help with this this error keeps popping up on line 20 invalid operands of types `int' and `int ()(int)' to binary `operator-' is there any help i can get please help me!!! thank you...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.