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
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
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
}
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
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.
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.
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.
#include <iostream>
// You may be missing headers here
usingnamespace 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;
}