Why doesnt this program Work?

Write your question here.




#include <iostream>
#include <string>
#include <time.h>
using namespace std;

int main(){
srand(time(NULL));
int x ;
x=6;


cout << " * NUMBERS * ";

cout << "You need atleast two players and one six-sided die ";

cout << " - INSTRUCTIONS - " <<endl;

cout << " 1. Take turns rolling all three die" <<endl;

cout << " 2. Add the numbers up" <<endl;

cout << " 3. If the sum is an even number you get two points, if it is odd you get one point" <<endl;

cout << " 4. First peron to 10 points wins!" <<endl;

cout << rand() % x+1;


int v;
v=rand() % x+1;


if ( v==1|| v==3|| v==5 )

{
cout << "Congratulations , YOU GET ONE POINT!";


}
else

{

if ( v==2 || v==4 || v==6 )

}

cout << "Congratulations , YOU GET TWO POINTS!u ";

}
}
You have many syntax errors in your code:

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
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <ctime> //it is <ctime> in the standard library
using namespace std;

int main()
{

srand(time(nullptr)); //use nullptr
int x = 6; //Initialization


cout << " * NUMBERS * ";

cout << "You need atleast two players and one six-sided die ";

cout << " - INSTRUCTIONS - " <<endl;

cout << " 1. Take turns rolling all three die" <<endl;

cout << " 2. Add the numbers up" <<endl;

cout << " 3. If the sum is an even number you get two points, if it is odd you get one point" <<endl;

cout << " 4. First peron to 10 points wins!" <<endl;

cout << rand() % x+1;


int v;
v=rand() % x+1; //I would recommend using C++14 random number 
//generation, but you probably haven't learned that yet. So this is fine.


if ( v==1|| v==3|| v==5 )
cout << "Congratulations , YOU GET ONE POINT!";

else if ( v==2 || v==4 || v==6 )
cout << "Congratulations , YOU GET TWO POINTS!u ";

}
Last edited on
Please explain the "doesn't work" in detail.


PS. Add code tags to your post. They make the code more readable. See http://www.cplusplus.com/articles/jEywvCM9/
Indent the code too.
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
#include <iostream>
#include <cstdlib>  // YOU NEED THIS

#include <string>
#include <time.h>
using namespace std;

int main()
{
    srand(time(NULL));
    int x,v ;
    x = 6;

    cout << " * NUMBERS * ";
    cout << "You need atleast two players and one six-sided die ";
    cout << " - INSTRUCTIONS - " <<endl;
    cout << " 1. Take turns rolling all three die" <<endl;
    cout << " 2. Add the numbers up" <<endl;
    cout << " 3. If the sum is an even number you get two points, if it is odd you get one point" <<endl;
    cout << " 4. First peron to 10 points wins!" <<endl;

    v=rand() % x+1;
    cout << "random number is: " << v << endl;

    if ( v==1|| v==3|| v==5 )
    {
        cout << "Congratulations , YOU GET ONE POINT!";
    }
    if ( v==2 || v==4 || v==6 )
    {
        cout << "Congratulations , YOU GET TWO POINTS! " << endl;
    }

}
Last edited on
Topic archived. No new replies allowed.