| | |
Anyone can do this in C++
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2007
Posts: 18
Reputation:
Solved Threads: 0
Write a program that simulates a lottery. The program should have an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element in the array. The user should enter five digits which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that match. For example, the following shows the lottery array and the user array with sample numbers stored in each. There are two matching digits (elements 2 and 4).
lottery array:
5 2 6 9 1
user array:
1 3 6 8 1
The program should display the random numbers stored in the lottery array and the number of digits matching digits. If all of the digits match, display a message proclaiming the user as a grand prize winner.
lottery array:
5 2 6 9 1
user array:
1 3 6 8 1
The program should display the random numbers stored in the lottery array and the number of digits matching digits. If all of the digits match, display a message proclaiming the user as a grand prize winner.
If anyone can do this in C++ then why can't you?
PS: You were wrong, anyone includes me, and I don't know C++ well enough to do this.
PS: You were wrong, anyone includes me, and I don't know C++ well enough to do this.
It is very important to read this: http://www.catb.org/~esr/faqs/smart-questions.html
If you don't know C++ well enough to even give it a try, you should just step back and learn the basics, give this problem a try and come back if you have some issues. Because there is no way someone is gonna teach you C++ language in one post here.
Are you Agile.. ?
•
•
Join Date: Jun 2007
Posts: 18
Reputation:
Solved Threads: 0
•
•
•
•
If you don't know C++ well enough to even give it a try, you should just step back and learn the basics, give this problem a try and come back if you have some issues. Because there is no way someone is gonna teach you C++ language in one post here.
this is my program..
c Syntax (Toggle Plain Text)
#include<iostream> using std::cout; using std::cin; using std::endl; #include <cstdlib> #include <ctime> int main() { int a; int b; int c; int d; int e; int A; int B; int C; int D; int E; cout << "Please Enter 1st Number of Your Prediction" << endl; cin >> A; while (A < 0) { cout << "\nInvalid Number Enter" << "Please Renter 1st Number of Your Prediction\n"; cin >> A; break; } cout << "\nPlease Enter 2nd Number of Your Prediction" << endl; cin >> B; while (B < 0) { cout << "\nInvalid Number Enter" << "Please Renter 2nd Number of Your Prediction\n"; cin >> B; break; } cout << "\nPlease Enter 3rd Number of Your Prediction" << endl; cin >> C; while (C < 0) { cout << "\nInvalid Number Enter" << "Please Renter 3rd Number of Your Prediction\n"; cin >> C; break; } cout << "\nPlease Enter 4th Number of Your Prediction" << endl; cin >> D; while (D < 0) { cout << "\nInvalid Number Enter" << "Please Renter 4th Number of Your Prediction\n"; cin >> D; break; } cout << "\nPlease Enter 5th Number of Your Prediction" << endl; cin >> E; while (E < 0) { cout << "\nInvalid Number Enter" << "Please Renter 5nd Number of Your Prediction\n"; cin >> E; break; } srand ( time(0) ); a = ( rand()%10 ); b = ( rand()%10 ); c = ( rand()%10 ); d = ( rand()%10 ); e = ( rand()%10 ); cout << "\nUser Array" << endl; cout << "---------------------" << endl; cout << "| " << A << " | " << B << " | " << C << " | " << D << " | " << E << " | " << endl; cout << "---------------------" << endl; cout << "\nLottery Array" << endl; cout << "---------------------" << endl; cout << "| " << a << " | " << b << " | " << c << " | " << d << " | " << e << " | " << endl; cout << "---------------------" << endl; { if (a == A) cout << "\n1st number is correct" << endl; else (a =! A); cout << "\n1st number is wrong" << endl; } { if (b == B) cout << "\n2nd number is correct" << endl; else (b =! B); cout << "\n2nd number is wrong" << endl; } { if (c == C) cout << "\n3rd number is correct" << endl; else (c =! C); cout << "\n3rd number is wrong" << endl; } { if (d == D) cout << "\n4th number is correct" << endl; else (d =! D); cout << "\n4th number is wrong" << endl; } { if (e == E) cout << "\n5th number is correct" << endl; else (e =! E); cout << "\n5th number is wrong" << endl; } return 0; }
Last edited by WaltP; Jun 26th, 2007 at 3:46 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
•
•
Join Date: Jun 2007
Posts: 33
Reputation:
Solved Threads: 1
Hey !!! I suggest you to come with an algorithm or psuedocode for your problem and one of us here would let you know where you are wrong or what is missing link in the same.
Do not worry abt the nature of the psuedocode - let it be in simple engish language in stepwise sequence -- but come out with one.
you can then go ahead and put the same in coding.
Do not worry abt the nature of the psuedocode - let it be in simple engish language in stepwise sequence -- but come out with one.
you can then go ahead and put the same in coding.
![]() |
Other Threads in the C++ Forum
- Previous Thread: 'Segmentation Fault'
- Next Thread: Parted in C++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






