c programming structure error - c

I have a few issues with my syntax, it mainly says i have an errror before "struct" on the line "Struct CustomerInfo s; but i dont seem to find the problem.
My program is supposed to ask what the person would like to do first of all, they can store a record for the first option which is then stored in a structure which can be viewed by selecting the 2nd option of the menu, if they select the 3rd then they obviously quit the program.
any help would be appreciated thank you.
#include <stdio.h>
void menu();
int id,first,last;
struct CustomerInfo
{
char FirstName[15]; /* These are the varibles for the customer infomation */
char LastName[20];
int ID;
};
int main()
{ /* program starts */
int selection = 0;
void menu()
{ /* Menu loop function */
do
{ /* menu start */
printf("\n\n - What would you like to do?");
printf("\n1 - Store a customer record");
printf("\n2 - View customer Records");
printf("\n3 - Quit program");
scanf("%i", &selection);
} while (selection > 3);
printf("You have entered an incorrect value"); /* If selection is greater than 3 then end program */
return 0;
}
switch(selection)
{
/* switch statement starts */
case 1:
struct CustomerInfo s;
printf("Please enter the customers details including First name, Lastname and ID.\n\n");
printf("Enter First name: ");
scanf("%s", s.FirstName); /* Option 1: Asks to enter the customers details to store then loops back to program */
printf("Enter Last name: ");
scanf("%s", s.LastName);
printf("Enter Customer ID: ");
scanf("%s", s.ID);
void menu();
break;
case 2:
printf("\nDisplaying Infomation\n");
printf("First name: %s\n",s.Firstname); /* Option 2: Prints the customer details as listed in option 1 */
printf("Last name: %s\n",s.Lastname);
printf("Customer ID: %s\n",s.ID);
void menu();
break;
case 3: /* Option 3: Program ends if option 3 is chosen. */
break;
}
return 0;

Let's start by looking at the structure you created; next we'll try to see if it can be fixed.
I am leaving details out so we can see the big outline:
main {
struct{}
void menu(){
do {
stuff
} while (selection > 3)
printf("you have entered an incorrect value"); // if selection is > 3
}
switch(selection) {
// do something if selection is 1 or 2, exit if 3
}
There is no final closing brace in your code. I am assuming that's a copy-paste error, so I added it. Compiling with -Wall (to get warnings as well as errors reported), I get a number of errors:
sel.c:18: error: nested functions are disabled, use -fnested-functions to re-enable
sel.c: In function ‘menu’:
sel.c:31: warning: ‘return’ with a value, in function returning void
sel.c: In function ‘main’:
sel.c:38: error: expected expression before ‘struct’
sel.c:41: error: ‘s’ undeclared (first use in this function)
sel.c:41: error: (Each undeclared identifier is reported only once
sel.c:41: error: for each function it appears in.)
sel.c:61: warning: control reaches end of non-void function
Let's take those in turn:
sel.c:18: error: nested functions are disabled, use -fnested-functions to re-enable
Putting one function inside another is "nesting". It is rare that you would want to do that - it means that the function is only "visible" when you are inside the other function (a bit like local variables, but for functions). It is not standard C - it is an extension of gcc. It's almost always a bad idea to use non-standard (and thus non-portable) extensions. See http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
sel.c: In function ‘menu’:
sel.c:31: warning: ‘return’ with a value, in function returning void
When we declare a function void, we say that it will not return a value. When you have a statement like return 0; you ARE returning a value. The compiler will ignore that - but it warns that you said one thing, and did another. Just use return; without a parameter, and the warning goes away.
sel.c:38: error: expected expression before ‘struct’
sel.c:41: error: ‘s’ undeclared (first use in this function)
sel.c:41: error: (Each undeclared identifier is reported only once
sel.c:41: error: for each function it appears in.)
This is the trickiest one. You would expect that you were properly declaring a variable s in line 38 - but the compiler complains. The reason for this is explained in the excellent Q&A at
Why can't variables be declared in a switch statement?
As an aside - if you COULD declare a variable like this - what are you doing with it? Your code currently reads in values, and returns. But as soon as you leave the "scope" of the variable (in your case, since you declared s inside the switch, that would be its scope) the variable disappears (the memory that was used for it is marked "free" and will be re-used.)
sel.c:61: warning: control reaches end of non-void function
This says that you have reached the end of a function that expects to return a value, but you don't have a return someValue; type of statement. Again - this only causes a warning, since the default behavior is to return 0 if no value is given, but it's a sign that you said one thing and did another.
So far I've just explained the errors that the compiler gave. Let's look more closely at the code structure. What I think you want to do is something like this:
define customerInfo structure
define menu function
main()
repeat:
call menu, get selection
switch(selection):
case 1: create new record
case 2: display records
case 3: quit program
In order to make this work, we need to make some changes to your program. First - let's move the menu function definition outside of the main function so we have portable code. Second - if we want to be able to create multiple customer records, we need to store them in an array. Really you would want a list so you can extend indefinitely, but let's keep it simple and allow a maximum of 10 records. Then we need to improve the logic of the menu function (if selection is not 1, 2 or 3 you give a message and try again; in your current code the line
printf("You have entered an incorrect value");
doesn't get executed until you have exited the loop that tested for incorrect values… so when you finally get there, the value is valid, not invalid.
Before we actually get to writing the "correct" code, there's another thing worth noting. When you read values using scanf, you do things like:
scanf("%s", s.FirstName);
which is correct, since s.FirstName is a pointer to the start of a string. However, you allocated a finite amount of space to your string (namely, 15 characters including the terminating '\0') so if someone enters a long name, your program will crash. "Good defensive coding" demands that you catch this - use for example
scanf("%14s", s.FirstName);
This says "read no more than 14 characters". There are better tricks but at least this is a start. However, you actually make a mistake when you do
scanf("%s", s.ID);
Since ID was defined as an int, and now you are reading a string into… not just its address, but into some location that is pointed to by the value of s.ID . This is very likely to give you a segmentation error (accessing memory that "isn't yours"). You should be doing:
scanf("%d", &s.ID);
"Read an integer into the location of s.ID"
Also - in some places you use FirstName, while in others you use Firstname. Ditto LastName. Capitalization matters - when you fix other compiler errors, these will start to show up.
Since you seem to want to be able to read in more than one customer record, we need an array of records; as I said above, we have to make sure the array is available in the scope of the switch statement, and "survives" that statement (so you can do something with it). Taking all these things together gets us to something like this:
#include <stdio.h>
// define function prototype:
int menu();
struct CustomerInfo
{
char FirstName[15]; /* These are the variables for the customer infomation */
char LastName[20];
int ID;
};
int menu()
{ /* Menu loop function */
int flag = 0;
int selection;
do
{ /* menu start */
if(flag > 0) printf("You have entered an incorrect value"); /* If selection is greater than 3 then end program */
printf("\n\n - What would you like to do?");
printf("\n1 - Store a customer record");
printf("\n2 - View customer Records");
printf("\n3 - Quit program\n>> ");
scanf("%i", &selection);
flag++;
} while (flag < 10 && (selection < 0 ||selection > 3));
return selection;
}
int main(void)
{ /* program starts */
struct CustomerInfo s[10];
int selection;
int customerCount = 0;
while(1) {
int ii; // loop counter we will need later
selection = menu();
switch(selection)
{
case 1:
printf("Please enter the customers details including First name, Lastname and ID.\n\n");
printf("Enter First name: ");
scanf("%s", s[customerCount].FirstName); /* Option 1: Asks to enter the customers details to store then loops back to program */
printf("Enter Last name: ");
scanf("%s", s[customerCount].LastName);
printf("Enter Customer ID: ");
scanf("%d", &s[customerCount].ID);
customerCount++;
break;
case 2:
printf("\nDisplaying Infomation\n");
for(ii = 0; ii < customerCount; ii++) {
printf("First name: %s\n",s[ii].FirstName); /* Option 2: Prints the customer details as listed in option 1 */
printf("Last name: %s\n",s[ii].LastName);
printf("Customer ID: %d\n---\n",s[ii].ID);
}
break;
case 3: /* Option 3: Program ends if option 3 is chosen. */
return 0; // program returns
break;
}
}
}
Test output:
- What would you like to do?
1 - Store a customer record
2 - View customer Records
3 - Quit program
>> 1
Please enter the customers details including First name, Lastname and ID.
Enter First name: John
Enter Last name: Smith
Enter Customer ID: 123
- What would you like to do?
1 - Store a customer record
2 - View customer Records
3 - Quit program
>> 5
You have entered an incorrect value
- What would you like to do?
1 - Store a customer record
2 - View customer Records
3 - Quit program
>> -1
You have entered an incorrect value
- What would you like to do?
1 - Store a customer record
2 - View customer Records
3 - Quit program
>> 1
Please enter the customers details including First name, Lastname and ID.
Enter First name: Harry
Enter Last name: Jones
Enter Customer ID: 654
- What would you like to do?
1 - Store a customer record
2 - View customer Records
3 - Quit program
>> 2
Displaying Infomation
First name: John
Last name: Smith
Customer ID: 123
---
First name: Harry
Last name: Jones
Customer ID: 654
---
- What would you like to do?
1 - Store a customer record
2 - View customer Records
3 - Quit program
>> 3

Related

C: Initialize variable to random # b/w 50 & 100 so they can be used in Switch statement if user selects an option that doesn't include entering values

So i'm very much a beginner and this is an assignment for class, but i'm not looking to have someone do the assignment for me or anything. Just help on a part i'm having trouble with.
I'm not posting my code as it's an ongoing assignment and I don't want someone to happen upon it and copy it ): But the gist of it is I need to display a menu to the user and create a switch statement. Each case has a corresponding function prototype that executes the choice the user made from the menu.
1 Enter 3 grades
2 Show average (with 3 grades) and letter grade
3 Show highest grade
4 Show lowest grade
5 Exit
I've done pretty much all of the assignment, but the one requirement I can't figure out is how to initialize the 3 grade variables to random numbers between 50 and 100, so if the user chooses menu options 2 3 or 4 first then those random #'s are what is used in my prototypes. But if the user chooses menu option 1, my functions should use the 3 values input by the user from that point until exit, or if they hit 1 again to input new values.
Since I couldnt figure it out I just had each prototype prompt the user to insert 3 grades then proceed to do its assigned task using those values.
We were also instructed to not use arrays as we havent gotten to that yet.
If no one is able to figure it out without seeing the code i'll wait until after the due date and post what I was able to do. i'm honestly just wanting to learn and my professor doesn't really post any videos or lectures (online class) so we just go off our textbook and good ol google.
Thank you to whoever can help(:
If you want a variable with a random standard value, initialize it with a random value. You can generate a random integer between two numbers using the random() function in the stdlib.h header.
Your code can be structured like this.
#include<stdlib.h>
#include<time.h>
int random_range(int start, int end) {
return start + (int) ((double) random() / RAND_MAX * (end - start));
}
int main() {
srandom(time());
int grade1 = random_range(50, 100);
int grade2 = random_range(50, 100);
int grade3 = random_range(50, 100);
...
}
Now the three grade variables are always initialized and can be used. I recommend, you also read the man page for the random() function.
Not a good idea, doing processing with some randomly assigned data simply to not do the work of controlling the user's options. Imagine that one option is to write the current record into persistent storage. Do you want to risk random valued records polluting the company's database? There are stories of "test versions" that have been released "into the wild" (on the day the coder was home with a cold, but management applied pressure to ship) that... well, that would curl your toes.
Here is a sketch whereby the user has two options only: enter the data or quit the program. Presuming valid data has been accepted, the menu features more options.
Do not process junk. It'll come back to bite you.
/* Usual header files */
int main() {
char buf[ 64 ];
int hiMenuOpt = 1;
do {
printf(
"Here's menu options\n"
"0: Quit\n"
"1: Enter data\n"
);
if( hiMenuOpt > 1 )
printf(
"2: Something\n"
"3: Something else\n"
"4: Something other\n"
);
printf( "Select 0-%d : ", hiMenuOpt );
fgets( buf, sizeof buf, stdin );
int val = strtol( buf, NULL, 10 ); // Edit fix. Thanks to Lundin
if( val < 0 || hiMenuOpt < val ) {
printf( "Bad entry\n" );
continue;
}
switch( val ) {
case 0:
hiMenuOpt = 0;
break;
case 1:
puts( "Hi from one\n" );
/* yadda yadda */
hiMenuOpt = 4;
break;
/* More stuff */
}
} while( hiMenuOpt );
return 0;
}
Here's menu options
0: Quit
1: Enter data
Select 0-1 : 1
Hi from one
Here's menu options
0: Quit
1: Enter data
2: Something
3: Something else
4: Something other
Select 0-4 :
Notice that Quit is now item 0. New menu items may be added, and old ones removed. The only constant is exiting the program. It makes sense, imo, to make that the first item on the list.

How to printf the value of input by user multiple times

I'm doing my c assignment and I have faced some problems. One of it is that I can't printf the value that are retrieved from the user. The value retrieved is in for loop and for the output it only shows the latest value that are entered by user. For this project, I can't use array or function. Someone please help me :(
printf("\n\nPlease Enter the number of bookings that you would like to make : ");
scanf("%d" , &noOfBooking );
//for control structures
for(i=1; i<=noOfBooking; i++){
printf("\nBooking %d" , i);
printf("\nSelect Room Type Option: ");
scanf("%d" , &option);
printf("Number of days: ");
scanf("%d" , &days);
printf("Number of person staying in the room: ");
scanf("%d" , &noPerson);
//selection structures
if(option==1)
{
ratePerDay = 75.00;
countSB--;
}
else if(option==2)
{
ratePerDay = 80.00;
countQB--;
}
else if(option==3)
{
ratePerDay = 100.00;
countKB--;
}
else if(option==4)
{
ratePerDay = 150.00;
countFR--;
}
else
printf("You have entered invalid input");
printf("Your Payment Booking are as follows :");
printf("\nRoom Type Option %d", option);
}
The expected output should be like this: -
Please Enter the number of bookings that you would like to make : 2
Booking 1
Select Room Type Option: 1
Number of days : 2
Number of person staying in the room : 1
Total Cost : 150.00
Booking 2
Select Room Type Option: 4
Number of days : 1
Number of person staying in the room : 3
Total Cost : 150.00
Your Payment Booking are as follows :
Room Type Option 1 (Single Bed) Total Cost is RM 150.00
Room Type Option 4 (Family Room) Total Cost is RM 150.00
I was thinking about using structs and the switch/case statement to solve your problem as they are not arrays or functions and you could store all the required information and afterwards handle the if/else if statements. For example:
// structs
// arguments related to your code
struct Booking {
int option;
int days;
int noPersons;
int num_of_Booking;
};
// switch-case
switch(option){
case 1:
ratePerDay = 75.00;
countSB--;
break; // optional - to terminate the switch statement
case 2:
...
.
.
case x:
...
default: // it works like the last else if your code
printf("You have entered invalid input");
As Paul said please provide some additional information on what you are trying to achieve in order for me to be more specific.
I hope that this helps you.
You can put every value in the same variable, for example, you can put the number 9 between every value that entered by the user.
For example if the user entered the options (1,3,2,2,4,3), the option value can be save in this way: option -> 193929294939
and than you will know every value that the user has entered.

Assignment to write a program that gives the user a choice between two options - C

I have an assignment due and I am drawing a blank on what exactly to do... I'm sure it is simple but I havent quite gotten the hang of things yet. The assignment is -
Write a program that gives the user 2 menu options: either call a function that will print a greeting and your name 4 times or call a function that will count down from 10 to 0 and then print "Blastoff!". Both functions should use for loops to print the appropriate output.
I have the prompt and the functions done so far... but I am unsure of how to display one or the other depending on the choice the user makes. Thank you for your help.
#include <stdio.h>
int main (void){
// declare counter variable
int i;
// prompt the user to make a choice
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n");
printf("\n");
// display greeting and name 4 times
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
printf("Blastoff!");
}
You should read the input from user's keyboard:
int c;
c = getchar();
if (c == '1')
{
// display greeting and name 4 times
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
}
if (c == '2')
{
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
}
printf("Blastoff!");
you should use Switch case.
switch(choice) {
case 1: //first for loop
break;
case 2: //second for loop
break;
}
Looks like you are missing a couple of points here. Firstly, you have not yet written any functions. Try looking here to gain some insight on that front.
Secondly, to make a choice based on user input you need to actually get that input somehow. You'll probably want to use scanf.
Lastly, once you have the user's input (say, in a variable declared as int input;) you can use if to control the flow of your program based on that variable like this:
if(input == 1){
greet();
}
else {
countDown();
}
Cheers! If you have any further questions feel free to comment below.
First of all you haven't actually declared you functions. Functions in C should be declared like the main function is. For more info in this see here.
// display greeting and name 4 times
void greeting(){
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
}
void countdown() {
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
printf("Blastoff!");
}
To get the user's input the most common way is by keyboard. scanf accomplishes that in C. Details on scanf here
int main(void){
int i, choice;
//prompt the user to make a choice
// You don't need 2 printf for the newlines stick them to one.
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n\n");
//This takes the user's input and puts it in the variable choice
scanf(%d, &choice);
}
Lastly to decide what to do based on the user input you can use either an if then else statement or a switch. I will provide a solution with an if statement and you can figure the one with the switch on your own. Your final code should look like this.
int main(void){
int i, choice;
//prompt the user to make a choice
// You don't need 2 printf for the newlines stick them to one.
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n\n");
//This takes the user's input and puts it in the variable choice
scanf(%d, &choice);
if(choice == 1){
greeting();
}else{
countdown();
}
}
// display greeting and name 4 times
void greeting(){
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
}
void countdown() {
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
printf("Blastoff!");
}
Bear in mind that this code has a lot of flaws (error checking mainly) but I guess your assigment is not about that.
First of all you need to include libraries with function you will need. You do this by
#include <someLibrary.h>
at the beggining of you document. Libraries mostly have .h extension. Always look for them if you try to do something. You consider them to have best performance and functionality as possible (not always true).
What is next you declare your functions. Function has name, arguments which are going into it, body in which they do something and return value (can be float, int, char etc). If function doesnt return anything, they return void (dont have return at the end). You declare functions before main() with only types of arguments. Whole body is after main (it is better looking).
If you declared function with arguments, you have to provide these arguments to function in () brackets. Even if no arguments are needed, you use them like getch() in example below. Note that function become what it return. If you declared some new variables in function they will be visible only in function. On the other hand function will not see any variable from other function (main too). If you want so, declare global variables (not recommended).
#include <stdio.h>
#include <conio.h> //libraries
void function1(int);
float function2(float); //declaration of functions
int main()
{
char decision;
printf("press 'a' to run function1, press 'b' to run function2\n");
decision=getch(); //first see getch()? look in google for functionality and library !
int someInt=10;
float someFloat=11;
if(decision== 'a')
{
function1(someInt);
}
else if(decision == 'b')
{
printf("%f", funcion2(someFloat)); //example that function become what they return
}
else
{
printf("No decision has been made");
}
getch(); //program will wait for any key press
return 0;
}
void function1(int param1)
{
//print your stuff // this function return void, so doesnt have return; statement
}
float function2(float param1)
{
return 2*param1; //this function have to return some float
}

Connect 4 game in C

For a small project we need to make a connect four game. Our project is broken up into several parts with each week we are assigned a different part to work on.
This week we have to make up the work on the columns by this I mean we have to use a function is called get_column, and use this to read a valid column number from the user where the next piece will be played.
So we were supplied the following files connect4.h (File used to store functions), week8_object.o (ignore the name its just the current week of sem), and week8.c which is the file I am currently editing.
Note 1: The comment in the code is what the lecturer wrote for us as a note.
When I am compiling I get an error saying undeclared identifier for the if(column_full(board, col)==FALSE) statement (FALSE part). I thought this was declared in the .h file?
EDIT- After some googling I have found that people silence that error by having this in the header. Is it correct to have this in coherence with the .h file?:
#include <stdio.h>
#include "connect4.h"
#define FALSE 0
#define TRUE 1
/* get_move
Prompts the user to enter a column, then checks that
- the column is in the valid range (1-COLS)
- that the column is not full (use function column_full to check)
If an invalid column is entered, the user is reprompted until it is valid
Returns the column number between 1 and COLS
*/
int column_full ( int board[COLS][ROWS], int col ) { return TRUE;}
int get_move ( int board[COLS][ROWS] ){
int col;
printf("Please enter a column number:");
scanf("%d",&col);
if(col>=1 && col<=COLS){
if(column_full(board, col)==FALSE){
printf("You have placed a token in the %d column\n",col);
}
else{
printf("That column is full");
}
}
while(col<=0 || col>COLS){
printf("Your token has not been placed");
printf("Please enter a valid column: ");
scanf("%d",&col);
}
return(col);
}
Header file:
#ifndef CONNECT4_H
#define CONNEXT4_H 1
#define ROWS 6
#define COLS 7
// displays the board to the screen
int display_board ( int[COLS][ROWS] ) ;
// sets up the board to an empty state
int setup_board ( int[COLS][ROWS] ) ;
// Returns TRUE if the specified column in the board is completely full
// FALSE otherwise
// col should be between 1 and COLS
int column_full ( int[COLS][ROWS], int col ) ;
// prompts the user to enter a move, and checks that it is valid
// for the supplied board and board size
// Returns the column that the user has entered, once it is valid (1-COLS)
int get_move ( int[COLS][ROWS] ) ;
// adds a token of the given value (1 or 2) to the board at the
// given column (col between 1 and COLS inclusive)
// Returns 0 if successful, -1 otherwise
int add_move ( int b[COLS][ROWS], int col, int colour ) ;
// determines who (if anybody) has won. Returns the player id of the
// winner, otherwise 0
int winner ( int[COLS][ROWS] ) ;
// determines if the board is completely full or not
int board_full ( int[COLS][ROWS] ) ;
#endif
There are few issues in your code:
In get_move() function, the given condition "If an invalid column is entered, the user is reprompted until it is valid" is not been taken care. You might want to use while loop in case of invalid column entered.
column_full() in your code is called without parameters. This function takes two parameters (refer to you .h file). So, don't forget to add them in call.
You have to use return(col) to take care of "Returns the column number between 1 and COLS"
I don't want to write a code for you. It would be helpful for you in long run, if you code yourself.
Now, to answer your question:
It is perfectly fine to have nested if-else statements.
From your original code:
}; /* <<-- problem 1 */
else() {
/* ^^^^ <<-- problem 2 */
printf("That column is full");
}
Remove these and your code will compile. I won't discuss the logic issues.
So in diff notation:
--- connect4.c.orig 2015-09-19 14:34:36.743337010 -0400
+++ connect4.c 2015-09-19 14:34:23.488222720 -0400
## -24,9 +24,9 ##
if(col>=1 && col<=COLS){
if(column_full(board, col)==FALSE){
- printf("You have placed a token in the %d column\n",col);
+ printf("You have placed a token in the %d column\n",col);
}
- else(){
+ else{
printf("That column is full");
}
}

error LNK2019: unresolved external symbol, fatal error LNK1120: 1 unresolved externals

I have looked both of these errors up on this website and tried to change my code to accommodate the changes that were suggested but they did not work for my code, so here is my code and I hope you guys can help me out. It is not complete as I am only about half way done with the assignment but I cannot see what I have done so far because it won't build correctly. Thank you!
#include <stdio.h>
//int CheckMoney(double *payment, double item_cost); //compares the amount the user has deposited to the price of item selected. It returns 1 if the amount is at least enough to cover the cost, 0 if there is not enough.
//void GetMoney(double *payment, double item_cost, char selection); //calls CoinMenu function to collect money from the user and CheckMoney function to keep comparing the deposited amount to the item cost.
//void GetChange(double *payment, double item_cost, double *change); //calculates the amount of change to be returned
void CoinMenu(double *payment);
void Quit(char *again);
void GetCost(char selection, double *item_cost);
void Menu(char *selection);
// Displays the list of snack items and prompts for the user’s choice
void Menu(char *selection)
{
printf("Welcome to the AAA vending machine, where your wishes could come true for less than $2");
printf("/nWhich one of our delicious snacks would you like to sink your teeth into?");
printf("/nP – Potato Chips $1.25");
printf("/nS - Snickers Bar $1.35");
printf("/nT – Pop Tart $0.95");
printf("/nC – Cookies $1.50");
printf("/nB – Brownie $1.75");
printf("/nN – Nuts $1.40");
printf("Enter your delicious selection here: ",*selection);
scanf(" %c", &*selection);
//determine cost of selection
GetCost(*selection, 0);
}
//sets the cost of the purchase based on value in selection
void GetCost(char selection, double *item_cost)
{
if(selection=='P'||'p')
{
*item_cost=1.25;
}
else if(selection=='S'||'s')
{
*item_cost=1.35;
}
else if(selection=='T'||'t')
{
*item_cost=0.95;
}
else if(selection=='C'||'c')
{
*item_cost=1.50;
}
else if(selection=='B'||'b')
{
*item_cost=1.75;
}
else if(selection=='N'||'n')
{
*item_cost=1.40;
}
else
{
printf("That is not a valid selection, have a nice day!");
return;
}
}
//displays menu of coins and gets user input of the coins deposited
void CoinMenu(double *payment)
{
printf("Please deposit your money by the following numbers:");
printf("/n1 - $5.00");
printf("/n2 - $2.00");
printf("/n3 - $1.00");
printf("/n4 - $0.25");
printf("/n5 - $0.10");
printf("/n6 - $0.05");
printf("/n7 - $0.01");
printf("/nAmount deposited: ");
scanf(" %c", &*payment);
}
void Quit(char *again)
{
printf("Would you like to buy another snack?");
printf("/nEnter Y for yes or N for no: ", *again);
if(*again=='N'||'n')
{
return;
}
else if(*again=='Y'||'y')
{
void Menu(char *selection);
}
}
For the error mentioned in your question - you have no main() function, and you don't have a complete C program until you write one. Your linker is looking for it, and giving you an error when it can't find it.
There's plenty of other errors here, too, including:
printf("/n1 - $5.00"); - it's \n, not /n, and it's not clear why you're putting the newline at the beginning of the line, instead of the end: printf("/nN – Nuts $1.40"); printf("Enter your delicious selection here: ",*selection); is going to give you some weird looking text, for instance.
Talking of which, printf("Enter your delicious selection here: ",*selection); - you provide a char as an argument to printf(), but according to your format string, it's not expecting any arguments. Should be printf("Enter your delicious selection here: "); Since you're not terminating it with a newline, you should also add an fflush(stdout); before your call to scanf().
scanf(" %c", &*selection); - why dereference a pointer only to take its address again? There are some good reasons not to, including the fact that it amounts to taking the address of a temporary value which is illegal. You already have a pointer, so use it - should be scanf(" %c", selection);
if(selection=='P'||'p') - binary logical operators don't work like that in C, should be if ( selection == 'P' || selection == 'p' ).
scanf(" %c", &*payment); - same issue with as point 3 above, plus here payment is a double *, and you're telling scanf() to read a char. Should be scanf("%lf", payment);
void Menu(char *selection); at the bottom - as pointed out in the comments to your main question, this is a function declaration, not a function call, and effectively does nothing here. Should be Menu(again), although really it should just return true or false, and the caller should decide whether or not to call Menu() again.
Several of these errors are repeated in various places throughout your code, I haven't listed every single example. This passing around of pointers is just really weird design, too. All of your functions are declared as returning void - if you changed them to return a value and employed some local variables, instead, you'd be able to avoid passing any pointers at all.

Resources