beginner lottery

I have been assigned to make a 2 number lottery game. The numbers can be the same, but not everytime. I have no idea what i'm doing. any advice would be great. thanks. heres my code:

// Lottery Number Game

#include <iostream>

// so we dont have to use std: anymore
using namespace std;


int main () // Start of program

{
int lotto1; // first lotto number
int lotto2; // second lotto number
int guess1; // users first guess
int guess2; // users second guess

lotto1 == srand 1 >= && <=10; // generates lotto number 1
lotto2 == srand 1 >= && <=10; // generates lotto number 2

cout << "Welcome to the Lottery"\n; // welcome screen

cout << " Enter your first integer guess between 1 and 10\n "; // promt for fisrt guess
cin >> guess1; // read first guess

cout << " Enter your secend intger guess between 1 and 10\n "; // promt for second guess
cin >> guess2; // read second guess

if (( guess1 == lotto1 || lotto2) && (guess2 == lotto1 || lotto2)) cout << " YOU WIN!\n"; // Winning Result

if (guess1 != lotto1 || lotto2) cout << " You LOSE! hahaha\n "; // Losing result

if (( guess1 == lotto1 || lotto2) || (guess2 == lotto1 || lotto2)) cout << " You got one of the numbers correct, but you still LOSE\n"; // Almost winning, but losing result

return 0; // end program
} // end function main
what should you do in the game? if you tell me i might post a code i have but i didn't understand..
basicly the user picks two numbers between 1 and 10. and its supposed to say if the user won, got one of the numbers right, or lost. also display the lottery numbers. doesnt matter the order. for example if i pick 5 and 6 and the lotter is 6 and 5 i still win.
@Alex: the idea is that the forum is for helping people, not for doing code for them, particularly when it's a homework assignment. Not only would using your code be plagiarism, it would also not serve to help others learn c++.

@OP: You are not properly generating a random number on lines 18 and 19. To generate a random number, you would need the following:

1
2
3
4
5
6
7
8
#include <stdlib.h>
#include <time.h>

int main()
{
    srand(time()); // srand( int ) seeds the random number generator with an int, most commonly used is time(), which will obviously change everytime the program is launched
    int x = rand() % 10; //will assign a random number from 0-9 to x. The random number generated has a large pool of numbers it can be, using the modulus operator we can define a smaller set
}
Intrexa wrote:
Not only would using your code be plagiarism

While I agree with the spirit of your reply, it can't be plagiarism if the author gives it to you.

More on topic, I just want to remind the OP that srand() is only meant to be called once. I often see people here calling it multiple times.
Last edited on
It's still plagiarism, if you don't cite the original source. You can even plagiarize yourself.
Last edited on
Webster wrote:
Definition of plagiarize:
transitive verb
: to steal and pass off (the ideas or words of another) as one's own
intransitive verb
: to commit literary theft


I hope this settles the not-quite-a debate. :)

-Albatross
Last edited on
In an academic setting, it is still considered plagiarism even if it comes from your own works. You can and will fail the course if you submit the same paper, or even the same paragraph to 2 separate professors.

Furthermore, if you sell the rights, it would be considered plagiarism to use them without the companies permission. Your ideas, but you can't use them anymore.
Last edited on
I have no idea what i'm doing. any advice would be great.


Well if you don't know what you're doing ,you might want to read the tutorial on this website,because it explains things pretty well.And i have to point out that you have quite a few comments in your code.This is always a good thing.
@Intrexa
Where would that academic setting be? I ask because if not citing yourself as a source can get you in trouble, then that's a lot harsher than what I had to deal with. Someone might get downgraded for laziness, but not plagiarism.

-Albatross
From a teacher at assumption college: http://chronicle.com/article/Plagiarizing-Yourself/124781/ blogging about the idiocy of telling students they can plagiarize themselves. I don't agree with it either, but that's what their faculty got told. At my school ( a community college) 2 different professors told me not to plagiarize myself this semester. I'm sure if you looked around more, you would find more stories.
@intexa
calm down, i just wanted to know because the ide dev-c++ gives an example program where you need to find a secret number..
Comments added. These are your main problems.
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
43
44
45
46
47
48
#include <iostream>
// You may be missing headers here

using namespace std; 

int main () 
{
	int lotto1; 
	int lotto2; 
	int guess1; 
	int guess2; 
	
	// These lines contain an error. What is srand? 
	// You aren't calling srand here are you?
	// The function for random numbers is in the <cstdlib> lib called rand()
	// If you want different numbers every game you need to use 
	// srand((unsigned)time(0)) at the beginning of main.
	// You'll need the <cstdlib> and the <ctime> headers.
	// Until then these lines are broken.
	
	//lotto1 == srand 1 >= && <=10;
	//lotto2 == srand 1 >= && <=10;

	cout << "Welcome to the Lottery\n"
		"Enter your first integer guess between 1 and 10\n";
	cin >> guess1;

	cout << "Enter your secend intger guess between 1 and 10\n";
	cin >> guess2;
	
	// Broken logic here. You need to have a full logic expression on both sides
	// Of any logical bool expression. None of (num == 1 || 2), but 
	// (num == 1 || num == 2)
	// What you do here is you get a value of guess==lotto OR lotto2, and if
	// lotto2 is anything but 0 its true. So you'll always get the conditon.
	if (( guess1 == lotto1 || lotto2) && (guess2 == lotto1 || lotto2)) 
		cout << "YOU WIN!\n";
	
	// You repeat the inconsistancy here
	if (guess1 != lotto1 || lotto2) 
		cout << "You LOSE! hahaha\n ";
	
	// You repeat the inconsistancy here
	if (( guess1 == lotto1 || lotto2) || (guess2 == lotto1 || lotto2)) 
		cout << "You got one of the numbers correct, but you still LOSE\n";
	
	return 0;
} 
Thank you all for the advice. I've got it figured out for the most part. except how to get the "and" sign to work. for example:

if (guess1 == lotto1) && (guess2 == lotto2); cout << " YOU WIN!\n "; // Winning Result

I keep getting an error in this spot.
Is it always printing YOU WIN?
Its because you have a strangler ; at the end of the if statement.
...lotto2); cout... // The semicolon here
no its a problem with the && because there is a red line under them and it tells me thats where the error occurs
change it to this

if ((guess1 == lotto1) && (guess2 == lotto2)); cout << " YOU WIN!\n ";

and then you'll get the error that wolfgang explained.

edit: but loose the compiler error.
Last edited on
Thank you all so much, I finally figured it out. I needed extra parenthesis marks. Program fixed and works. Thanks
Topic archived. No new replies allowed.