Having trouble getting this code to print 1 seat then loop back to user prompt. it should loop back until the seats are filled then display first class/ecoomy full. this is the code i have so far.
int main(int argc, char** argv) {
const int firstClass[] = {1, 2, 3, 4}; //first class array list
const int economyClass[] = {5, 6, 7, 8, 9, 10, 11, 12}; //economy array list
int firstLen = 4; // first class length
int economyLen = 8; //economy class length
int userInput;
int i;
//user prompt
printf("Please type 1 for First Class\n");
printf("Please type 2 for Economy\n");
printf("Please type 0 to Quit\n");
printf("\n");
scanf("%d", &userInput); // scanning for user input
if(userInput == 1){
for(i = 0; i < 4; i++){
if(i < firstLen){
printf("Class: First Seat Number: %d\n", firstClass[i]);
}
else{
printf("First Class is Full. Next flight is tomorrow.");
}
}
}
if(userInput == 2){
for (i = 0; i < 8; i++){
if(i < economyLen){
printf("Class: Economy Seat Number: %d\n", economyClass[i]);
}
else{
printf("Economy is Full. Next flight is tomorrow.");
}
}
}
}
As you want to take input from user as long as userInput != 0, so you need to take user input within a loop.
This loop will break when userInput will be 0.
Now about printing available seat from firstClass and economyClass, you can maintain 2 variables through which you keep track of last printed seat. Just like you maintain indexing while printing values of an array.
Here's a sample code. I've given some inline comments for better understanding.
int main(int argc, char** argv) {
const int firstClass[] = {1, 2, 3, 4}; //first class array list
const int economyClass[] = {5, 6, 7, 8, 9, 10, 11, 12}; //economy array list
int firstLen = 4; // first class length
int economyLen = 8; //economy class length
int firstClassSeatNumber = 0;
int economyClassSeatNumber = 0;
int userInput;
int i;
while(true) {
//user prompt
printf("Please type 1 for First Class\n");
printf("Please type 2 for Economy\n");
printf("Please type 0 to Quit\n");
printf("\n");
scanf("%d", &userInput); // scanning for user input
if (userInput == 0) {
break; // breaking the loop as we won't take further input from user
}
if(userInput == 1) {
if (firstClassSeatNumber < firstLen) {
// if we've any seat left in first class, then we'll print it
printf("Class: First Seat Number: %d\n", firstClass[firstClassSeatNumber]);
firstClassSeatNumber++; // moving to next seat of first class
}
else {
// don't have any seat left in first class
printf("First Class is Full. Next flight is tomorrow.");
}
}
else if(userInput == 2) {
if (economyClassSeatNumber < economyLen) {
// if we've any seat left in economy class, then we'll print it
printf("Class: Economy Seat Number: %d\n", economyClass[economyClassSeatNumber]);
economyClassSeatNumber++; // moving to next seat of economy class
}
else {
// don't have any seat left in economy class
printf("Economy is Full. Next flight is tomorrow.");
}
}
}
}
Related
This is the code that I have. Currently the code prints out all the seats at once. I need it to print one seat and then restart to the user prompt. it can not assign the same seat and should show first class full when there are no more seats.
int main(int argc, char** argv) {
int firstClass[] = {1, 2, 3, 4}; //first class array
int firstLen = 4; // first class length
int userInput;
int i;
//user prompt
printf("Please type 1 for First Class\n");
printf("Please type 2 for Economy\n");
printf("Please type 0 to Quit\n");
printf("\n");
scanf("%d", &userInput); // scanning for user input
if(userInput = 1){
for(i = 0; i < 4; i++){
if(i < firstLen){
printf("Class: First Seat Number: %d\n", firstClass[i]);
}
else{
printf("First Class Full. Next flight is tomorrow.");
}
}
}
}
You can track which seats are taken with a variable. Each time a user selects 1 print out the seat number for that index, and then increment the index.
You'll then wrap this in a loop (for or while) and only exit the loop when the user enters 0. Make sure you define the variable used to track the current index outside of the loop.
Something like this:
int main(void)
{
const int first_class[] = {1, 2, 3, 4};
const size_t first_class_size = sizeof(first_class) / sizeof(first_class[0]);
size_t first_class_index = 0;
int user_input = 0;
do
{
print_menu();
scanf("%d", &user_input);
if (user_input == 1)
{
if (first_class_index < first_class_size)
{
printf("Here is your ticket information:\n");
printf("Seat Number: %d, Class: First\n\n", first_class[first_class_index++]);
continue;
}
printf("No first class seats are available.\n\n");
}
} while(user_input != 0);
}
I have this program that is supposed to handle assigning seats to passengers.
I cannot figure out what is causing my seg fault. I am using an array of structs and that may be where the problem is coming from.
I think its probably a problem with dereferencing some struct members, but I can't find where.
Here is my code:
struct seat
{
// Max Name of 32 chars
char name[32];
// Seat Number
int sNum;
// Seat taken = 1, open = 0
int taken;
};
// Function headers
void seat(struct seat plane[][10]);
void mani(struct seat plane[][10]);
void pass(int seat, char name[], int class);
int main()
{
// My airline plane is 6 seats per row, 10 rows
// Row 1/2 are First Class
// Row 3/4 are Business Class
// Init counter variables to keep track of the number
// of First Class/Business seats already taken
// also the user input var
int input, ticketin, class1 = 0, class2 = 0, class3=0, sNum, i;
char namein[32];
// Vars for pass function
char passname[32];
int passclass;
int passseat;
// Init a 2d array 6 colums 10 rows
struct seat plane[6][10];
for (i=0; i<sizeof(plane); i++)
{
plane[i]->sNum = i+1;
plane[i]->taken = 0;
}
// Begin user input loop
// Menu with 3 options:
// Display the seating chart, indicating taken seats
// Display the manifest
// Display a boarding pass - seat number, name, class
do
{
do
{
// Prompt user for ticket selection
printf("Please type 1 for \"First Class\"\n");
printf("Please type 2 for \"Business Class\"\n");
printf("Please type 3 for \"Economy Class\"\n");
scanf(" %d", &ticketin);
// Check for valid input
if (ticketin == 1)
{
// Check to make sure first class is not full
if (class1 < 12)
{
class1 += 1;
printf("First class is open!\n");
} else {
printf("First class is full, please choose another class\n");
}
} else if (ticketin == 2)
{
// Check to make sure business class is not full
if (class2 < 12)
{
class2 += 1;
printf("Business class is open!\n");
} else {
printf("Business class is full, please choose another class\n");
if (class1 < 12)
{
printf("Upgrade to First Class by entering 1");
}
}
} else if (ticketin == 3)
{
// Check to make sure business class is not full
if (class3 < 12)
{
class3 += 1;
printf("Economy class is open!\n");
} else
{
printf("Economy class is full, please choose another class\n");
if (class1 < 12)
{
printf("Upgrade to First Class by entering 1");
}
if (class2 < 12)
{
printf("Upgrade to Business Class by entering 2");
}
}
} else
{
ticketin = 4;
}
// Prompt the user for their name
printf("Please input your name:\n");
scanf(" %s", namein);
} while (ticketin == 4);
// Handle loading the new passenger into plane array
switch (ticketin)
{
case 1:
for (i=0; i<12; i)
{
if (plane[i]->taken == 0)
{
plane[i]->taken = 1;
strcpy(plane[i]->name, namein);
sNum = plane[i]->sNum;
} else
{
i++;
}
}
case 2:
for (i=12; i<24; i)
{
if (plane[i]->taken == 0)
{
plane[i]->taken = 1;
strcpy(plane[i]->name, namein);
sNum = plane[i]->sNum;
} else
{
i++;
}
}
case 3:
for (i=24; i<60; i)
{
if (plane[i]->taken == 0)
{
plane[i]->taken = 1;
strcpy(plane[i]->name, namein);
sNum = plane[i]->sNum;
} else
{
i++;
}
}
}
printf("Menu Options: \n");
printf("(1) Display the seating chart\n");
printf("(2) Display the passenger manifest\n");
printf("(3) Display a boarding pass\n");
printf("(4) Quit\n");
// Prompt user for their selection
printf("Please enter your menu selection:\n");
scanf(" %d", &input);
// Switch case handling function calls
switch (input)
{
case 1:
seat(plane);
break;
case 2:
mani(plane);
break;
case 3:
printf("Please input a seat number\n");
scanf(" %d", &passseat);
if (passseat < 12)
{
passclass = 1;
} else if (passseat < 24)
{
passclass = 2;
} else
{
passclass = 3;
}
pass(passseat, plane[passseat-1]->name, passclass);
break;
default:
printf("invalid menu option or quitting\n");
break;
}
} while (input != 4);
}
// Display seating chart function
void seat(struct seat plane[][10])
{
int i, sNum;
for (i=0; i<sizeof(plane); i++)
{
if (plane[i]->taken == 1)
{
printf("Seat %d is taken\n", i++);
} else
{
printf("Seat %d is not taken\n", i++);
}
}
}
// Display Manifest function
void mani(struct seat plane[][10])
{
int i;
for (i=0; i<sizeof(plane); i++)
{
if (plane[i]->taken == 1)
{
printf("Passenger %s in seat %d\n", plane[i]->name, i++);
}
}
}
// Display boarding pass function
void pass(int seat, char name[], int class)
{
printf("Boarding pass for %s\n", name);
printf("Seat Number: %d\n", seat);
switch (class)
{
case 1:
printf("First Class");
break;
case 2:
printf("Business Class");
break;
case 3:
printf("Economy Class");
break;
}
}
There are probably other errors, but this is the most obvious one:
for (i=0; i<sizeof(plane); i++)
{
plane[i]->sNum = i+1;
plane[i]->taken = 0;
}
sizeof(plane) is the number of bytes in the plane array. This is 10 * 6 * sizeof(struct seat), so you're writing way outside the array. If you want to know the number of elements in an array, you have to divide the size of the array by the size of an array element:
for (i=0; i<sizeof(plane)/sizeof(*plane); i++)
{
plane[i]->sNum = i+1;
plane[i]->taken = 0;
}
But your code is only initializing the first element in each row of the array.
Since it's a 2-dimensional array, you need nested loops. And you should use normal member access with . rather than pointer indirection.
for (i=0; i<sizeof(plane)/sizeof(plane[0]); i++)
{
for (int j = 0; j < sizeof(plane[i])/sizeof(plane[i][0]); j++)
{
plane[i][j].sNum = i+1;
plane[i][j].taken = 0;
}
}
You could simplify all the sizeof stuff by defining macros:
#define ROWS 6
#define COLS 10
and then using these macros in the array declaration and the for loop limits.
Similar changes need to be made in other code that loops over the plane array.
I'm writing this program in c where I need to re-prompt the user after an invalid input. I came to a solution only to discover that if the user enters another invalid input after the re-prompt then it continues. Can someone please show me a better solution to this? I'll show you what I had anyway:
#include <stdio.h>
#include <ctype.h>
main()
{
int ctr; // loop counter
int custID[10] = {1, 3, 5, 9, 10, // ID array
6, 4, 7, 8, 2};
double custBal[10] = {153.56, 1300.45, 684.45, 990.45, 45.54, // Balance array
1100.34, 594.45, 1340.45, 1000.00, 1134.00};
int IDsearch; // For interaction
int found = 0; // Search criteria
int inner, outer, tempID, didSwap; // For sorting the arrays
double tempBal;
char ans;
/* Firs step: Sort the arrays for efficiency */
for(outer = 0; outer < 9; outer++) // <9 and not <10, because 9 numbers will be bubble sorted
{ // the highest (10th) will remain at the bottom
didSwap = 0; // Turns one after the arrays sort
for(inner = outer; inner < 10; inner++)
{
if(custID[inner] < custID[outer]) // Ascending sort
{
tempID = custID[inner]; // Must include both,
tempBal = custBal[inner]; // otherwise the arrays wont be linked
custID[inner] = custID[outer];
custBal[inner] = custBal[outer];
custID[outer] = tempID;
custBal[outer] = tempBal;
didSwap = 1; // Flag that a swap took place
}
}
if(didSwap == 0)
{
break;
}
}
/* Second step: Interacting with the program */
printf("***Customer Balance Search***\n");
do
{
printf("Which ID number do you want to check?\n");
scanf(" %d", &IDsearch);
for(ctr = 0; ctr < 10; ctr++)
{
if(IDsearch == custID[ctr])
{
found = 1;
break;
}
}
if(found)
{
if(custBal[ctr] < 1000)
{
printf("\nCustomer #%d has a balance of $%.2f.\n", custID[ctr], custBal[ctr]);
printf("Credit is good!\n");
}
else
{
printf("\nCustomer #%d has a balance of %.2f.\n", custID[ctr], custBal[ctr]);
printf("Credit is bad! No more credit!\n");
}
}
else
{
printf("\nCustomer #%d was not found!\n", IDsearch);
printf("Please enter a correct ID number!\n\n");
continue;
}
printf("\nDo you want to search another ID number?\n");
printf("Enter (Y)es or (N)o\n");
scanf(" %c", &ans);
ans = toupper(ans);
}
while((found != 1) || (ans == 'Y' && ans != 'N'));
printf("\nExiting...\n\n");
return (0);
}
Please reset found
do {
found = 0;
// ...
at the start of the do-while loop. It is not enough to initialise it when defined.
I am trying to copy the array winner from my function 'enter', so that i am able to just output it on the 'previous' function. When picking the option for the previous option I have gotten nothing outputting. Its only the last function named 'previous' that is not working, but to produce the problem the majority of the code is needed.
#include <stdio.h>
#include <string.h>
char enter(char names[][20]);
void menu();
void previous(char winner[][8]);
int main()
{
char names[16][20];
int i;
printf("Please enter the names of the players:\n");
/*Making the user enter 16 times*/
for (i = 0; i < 16; i++)
{
scanf("%9s", &names[i]);
fflush(stdin);
}
/*Clearing Screen*/
system("cls");
menu(names);
return names[16][20];
}
void menu(char names[][20], char winner[][8])
{
int choice;
printf("Please select one of the following options:\n\n"
"Press 1 to enter game results\n"
"Press 2 to display the current round\n"
"Press 3 to display the players advancing to the next round\n"
"Press 4 to display the previous round\n"
"Press 5 to exit the program\n");
scanf("%d", &choice);
if(choice == 1)
{
enter(names);
}
system("cls");
if(choice == 3)
{
previous(winner);
}
}
char enter(char names[][20])
{
int result;
int score1;
int score2;
int p, c, j, l, i;
char winner[8][8];
system("cls");
for(i = 0; i < 8; i++)
{
printf("\n\n%s vs %s",names[i],names[i+8]);
score1 = 0;
score2 = 0;
for(j = 0; j < 5; j++)
{
printf("\n\nEnter game %d results, press 1 if %s won or"
" 2 if %s won :\n",(j+1), names[i], names[i+8]);
scanf("%d", &result);
if(result == 1)
{
score1++;
}
if(result == 2)
{
score2++;
}
printf("\n\n1Current score is %d-%d", score1, score2);
if(score1 == 3)
{
printf("\n\n%s adavances to the next round!",names[i]);
strncpy(winner[i], names[i], 10);
printf("\n\nPress Enter to Continue");
getch();
system("cls");
break;
}
if(score2 == 3)
{
printf("\n\n%s adavances to the next round!",names[i+8]);
strncpy(winner[i], names[i+8], 10);
printf("\n\nPress Enter to Continue");
getch();
system("cls");
break;
}
}
}
system("cls");
printf("The players advancing to the next round are:\n\n");
for(p = 0; p < 8; p++)
{
for(c = 0; c < 8; c++)
{
printf("%c",winner[p][c]);
}
printf("\n");
}
printf("\n\nPress Enter to Continue");
getch();
system("cls");
menu(names, winner);
return winner[8][8];
}
void previous(char winner[][8])
{
int i, j;
for(i = 0; i < 8; i++)
{
for(j = 0; j < 8; j++)
{
printf("%c",winner[i][j]);
}
printf("\n");
}
}
There is no data for the array winner in your program! At least not when you call it for the first time.
The signature for the menu function is:
void menu(char names[][20], char winner[][8]);
but you call it from main like this:
menu(names);
The winner parameter is missing. This shouldn't happen, but you have declared a prototype for this function, namely:
void menu();
Unfortunately, C treats the empty parens as meaning "whatever parameters you pass", not as function that takes no parameters. That means that your function call slips by. The fix is to provide the correct signature for the prototype and also to pass a suitable winner array from main.
Strangely, your enter function provides a local array winner. This array will always be a new array when you call enter. That's probably not what you want. As is, your program should have one names and one winner array. (You can pass these arrays around, but you should make sure that tese arrays are consistent. Don't create new arrays when you really want to operate on existing ones.)
You also call your menu recursively. That means the you go ever deeper into the call structure without real benefit. Dont do that; use a loop instead: do display the menu while the user hasn't chosen "quit". (There are applications for recursive functions, but this isn't one.)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Develop a program that will play the Lotto game. The program should allow a user to
enter their 6 selected numbers and give them a set of options, each performing a
specific requirement. You must store the 6 numbers in a 1-Dimensional array.
There are a number of requirements that your program must meet. Your program
must be modularised (i.e. use functions) and each task should be dealt in a separate
function. The program should display a simple menu to the user and each option in
the menu will be implemented by calling a separate function. You must use pointer
notation to access array elements - NOT subscripts
The requirements are as follows (each implemented in a separate function):
Read the 6 selected numbers from the keyboard. Perform any necessary
validation (error-checking) required (e.g. all numbers must be different, range
1-42, etc.). THIS IS THE PART WHICH I CANNOT DO
Display the contents of the 1-D array containing your lotto numbers that you
entered.
Sort the contents of the array in increasing order (i.e. 1st element = smallest
number, 2nd element = 2nd smallest number, etc.). You may use any sorting
algorithm of your choice.
Compare your chosen lotto numbers in the 1-D array with the following
winning numbers:
1,3,5,7,9,11 - 42 (Bonus number)
5 Display the frequency of the numbers entered each time the user enters a new AND I HAVE NO CLUE HOW TO EVEN START THIS
set of numbers (without exiting the program) on the screen. For example, it
might display:
number 1 has been selected x times
number 7 has been selected x times
number 28 has been selected x times
etc.,
6 Exit program
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include <stdlib.h>
#define NUMBERS 6
// Declare Prototype
void getnumbers(int*);
void displaynumbers(int*);
void sortnumbers(int*);
void comparenumbers(int*,int*);
void frequencynumbers(int*);
void exit();
main()
{
int choice=0;
int lotto_no[NUMBERS];
int winning_no[NUMBERS]={1,3,5,7,9,11};
do
{
system("cls");
printf("\n======================MAGIC Lotto======================");
printf("\n\n\n--------------Use 1-6 to navigate the menu-------------");
printf("\n\n\n1.Pick your 6 lucky numbers");
printf("\n\n2.Disply your numbers");
printf("\n\n3.Display your lucky numbers in increasing order");
printf("\n\n4.Compare your numbers to see your prize!");
printf("\n\n5.Frequency of the numbers entered each time");
printf("\n\n6.Exit");
printf("\n\n\n========================================================");
printf("\n");
scanf("%d",&choice);
system("cls");//Clears the menu from the screen while we selesc an option from the Menu
if (choice == 1)
{
getnumbers(lotto_no);
}
if (choice == 2)
{
displaynumbers(lotto_no);
}
if(choice == 3)
{
sortnumbers(lotto_no);
}
if(choice == 4)
{
comparenumbers(lotto_no,winning_no);
}
if(choice == 5)
{
frequencynumbers(lotto_no);
}
if(choice == 6)
{
exit();
}
flushall();
getchar();
}
while(choice>1 || choice<7);
}
void getnumbers(int *lotto_no)
{
int i;
printf("Enter your numbers\n");
for(i=0;i<NUMBERS;i++)
{
scanf("%d", &*(lotto_no+i) );
if ( *(lotto_no+i) >0 || *(lotto_no + i ) <= 43 )
{
continue;
}
else
{
printf(" Please enter a value in between 1 and 42");
scanf("%d", &(*(lotto_no+i)));
}
}
}
void displaynumbers(int *lotto_num)
{
int i;
printf("Your lucky numbers are as follow:\n");
for(i=0;i<NUMBERS;i++)
{
printf("%d ",*(lotto_num+i));
}
}
void sortnumbers(int *lotto_num)
{
int i;
int j;
int temp;
for(i=0;i<NUMBERS;i++)
{
for(j=i;j<NUMBERS;j++)
{
if(*(lotto_num+i) > *(lotto_num+j))
{
temp=*(lotto_num+i);
*(lotto_num+i)=*(lotto_num+j);
*(lotto_num+j)=temp;
}
}
}
printf("Your lucky numbers are as follow:\n");
for(i=0;i<NUMBERS;i++)
{
printf("%d ",lotto_num[i]);
}
}
void comparenumbers(int *lotto_num,int *winning_num)
{
int i;
int j;
int c;
int b;
int g;
c=0;
b=42;
g=0;
for(i=0;i<NUMBERS;i++)
{
for(j=0;j<NUMBERS;j++)
{
if(*(lotto_num+i) == *(winning_num+j))
{
c++;
}
}
}
for(i=0;i<NUMBERS;i++)
{
if(*(lotto_num)==b)
{
g++;
}
}
if(c==6)
{
printf("JACKPOT!!!");
}
if(c==5)
{
printf("HOLIDAY!!!");
}
if(c==4)
{
printf("NIGHT OUT!!!");
}
if(c==3&&g==1)
{
printf("CINEMA TICKET!!!");
}
if(c==4&&g==1)
{
printf("WEEKEND AWAY!!!");
}
if(c==5&&g==1)
{
printf("NEW CAR!!!");
}
if(c<3)
{
printf("MAYBE NEXT TIME QQ :(");
}
}
void frequencynumbers(int *lotto_num)
{
}
void exit()
{
exit(0);
}
Your comparison is invalid:
if ( *(lotto_no+i) >0 || *(lotto_no + i ) <= 43 )
It means "if number is greater than 0 OR number is less or equal to 43.
Also you move on to the next number even if you enter incorrect number.
for(i=0;i<NUMBERS;)
{
int number = 0;
scanf("%d", &number);
// Replace OR with AND, and fix the upper comparison operator
if(number > 0 && number < 43 )
{
lotto_no[i] = number;
i++; // Only increase when number was correct
}
else
{
printf(" Please enter a value in between 1 and 42");
}
}
I'm trying task Number 1 & 5 here.
Lets see the first task
void getnumbers(int *lotto_no)
{
int i,j,temp;
printf("Enter 6 different numbers in the range 1-42\n");
for(i=0;i<6;i++)
{
printf("Enter number %d ",i+1);
scanf("%d",&temp);
for(j=0;j<i;j++)
{
while( (temp == *(lotto_no+j)) || (temp<1 || temp>42)) //Error checking
{
printf("Wrong input. Please enter a unique number in the range 1-42");
scanf("%d",&temp);
j=0;
}
}
*(lotto_no+i)=temp;
}
return
}
Now lets go for Task no 5. I'm taking another array int frequency[43]={0}. I'm creating another function void UpdateFrequency(int *, int *). In this frequnency will be updated and this will be called each time user enters a correct input combination i,e we should call this function in task 1.
void UpdateFrequency(int *lotto_no, int *frequency)
{
int i;
for(i=0;i<6;i++)
{
(*(frequency+(*(lotto_no+i))))+=1; //frequency[lotto_no[i]]+=1;
}
return;
}
void frequencynumbers(int *lotto_no, int *frequency)
{
int i;
for(i=0;i<6;i++)
{
printf("The frequency of number %d is %d\n",*(lotto_no+i),*(frequency+(*(lotto_no+i))));
}
return;
}
Here is one way you could go about answering your first question:
void getnumbers(int *lotto_no)
{
int i;
printf("Enter your numbers\n");
for(i=0;i<NUMBERS;i++)
{
do
{
printf("Please enter number %d, between 1 and 42\n", i+1);
scanf("%d", lotto_no+i); // or &lotto_no[i] if you prefer
}
while ( *(lotto_no + i) < 1 || *(lotto_no + i ) > 42 ); // or lotto_no[i]
printf("Number %d accepted\n", i+1);
}
}
I have removed the unnecessary & and * from your scanf as they are redundant. I reversed the inequalities so that the inner do while loop will continue for each number until a valid input is given.
An easy way to count the number of times a given number is entered would be to have an array of bins, one for each number. Then you could scanf into a temporary number and increment the corresponding element of bins:
void getnumbers(int *lotto_no)
{
int i, n, bins[42] = {}; // initialise zeroed array
printf("Enter your numbers\n");
for(i=0;i<NUMBERS;i++)
{
do {
printf("Please enter number %d, between 1 and 42\n", i+1);
scanf("%d", &n); // read into temporary variable
}
while ( n < 1 || n > 42 );
lotto_no[i] = n; // assign to lotto_no
++bins[n-1]; // increment corresponding counter
printf("Number %d accepted\n", i+1);
}
for(i=0; i<42; ++i)
{
if (bins[i] > 0) printf("number %d entered %d times\n", i+1, bins[i]);
}
}