Random Number Help

Ok, I am making a fake virus detector, but whenever it loads the virus it says 23 and 6, no matter how much times i try it. Also even though i added system pause it dosent pause

code:
#include <iostream>
#include <iostream>
using namespace std;

int main()
{
string a;.
string b;
string c;

int FV;
int RV;

FV = rand() % 30 + 10;
RV = rand() % 10;

cout << "My name is the Virus Detector!" << endl;
system("pause");
cout << "What is you name?" << endl;
cin >> a;
cout << "Hello, " << a << ". It is a pleasure to meet you!!" << endl;
cin >> b;
cout << "You are welcome!" << endl;
system("pause");
cout << "Wait a second, i'm scanning your system data!" << endl;
system("pause");
cout << "I have found " << FV << " viruses in your computer! " << RV << " of them are slowing your computer down right now!" << endl;
cout << "Would you like me to remove them?" << endl;
cin >> c;
cout << "Wait, I am being attacked by one of the-" << endl;
cout << "Terminator Virus Loaded" << endl;
return 0;
}

Please use code tags for your code - http://www.cplusplus.com/articles/jEywvCM9/

If you want different random number each time, you need to seed it.

Add this as an include #include <ctime> And put this somewhere on the top of your program srand(time(0));

And a few tips: Don't name your variables a b and c, name them something that describes what they are. And you don't need double iostream

1
2
#include <iostream>
#include <iostream> // remove this one 
I meant for it to be string, ty.
Also would i add srand(time(0)); into main?
Yes, anywhere before you start generating random numbers.

1
2
3
4
5
6
7
int FV;
int RV;

srand(time(0));

FV = rand() % 30 + 10;
RV = rand() % 10;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>
#include <time>
using namespace std;

int main()
{
string name;
string response1;
string response2;

int FV;
int RV;

srand(time(0));

FV = rand() % 30 + 10;
RV = rand() % 10;

cout << "My name is the Virus Detector!" << endl;
system("pause");
cout << "What is you name?" << endl;
cin >> name;
cout << "Hello, " << a << ". It is a pleasure to meet you!!" << endl;
cin >> response1;
cout << "You are welcome!" << endl;
system("pause");
cout << "Wait a second, i'm scanning your system data!" << endl;
system("pause");
cout << "I have found " << FV << " viruses in your computer! " << RV << " of them are slowing your computer down right now!" << endl;
cout << "Would you like me to remove them?" << endl;
cin >> response2;
cout << "Wait, I am being attacked by one of the-" << endl;
cout << "Terminator Virus Loaded" << endl;
return 0;
} 


Good?
That will give you random numbers each time yes.
Topic archived. No new replies allowed.