473,405 Members | 2,404 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,405 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 13769
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.