I am trying to create a multiple choice quiz so I can learn the menu at my new job, while doing a side project but I am having a warning when outputting. Can you guys take a look at this to see what it is? I would appreciate it. Its NOT homework, its a side project!
PS. Speaking of side projects, is this a kind of side project people are looking for on a resume?
Code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
typedef struct quiz
{
char question[20][100];
char answer[20];
} quiz;
// function prototypes
void create_boxed_menu();
void create_top();
void create_bottom();
void create_sides();
void drinks_was_selected();
void wine_was_selected();
int main()
{
int command_code, i, drink_category_selector;
printf("\n");
create_top();
create_boxed_menu();
create_sides();
printf("-\tYour selection is:\t\t\t\t\t\t -\n");
printf("\t");
scanf("%d", &command_code);
create_sides();
if (command_code == 1)
{
// Running the drink_was_selected function that displays the different category of drinks
drinks_was_selected();
printf("-\tWhich category of drinks would you like to be quizzed on:\t -\n");
printf("\t");
// Scanning in the users selection of drinks to be quizzed on
scanf("%d", &drink_category_selector);
// The selection is Wine
if (drink_category_selector == 1)
{
wine_was_selected();
}
// The selection is Beer
else if (drink_category_selector == 2)
{
}
// The selection is Crushes
else if (drink_category_selector == 3)
{
}
// The selection is Slushes
else if (drink_category_selector == 4)
{
}
// The selection is Shakers
else if (drink_category_selector == 5)
{
}
// The selection is House Specialties
else if (drink_category_selector == 6)
{
}
// The selection is Ultimates
else
{
}
for (i=0; i<2; i++)
create_sides();
}
else if (command_code == 2)
{
printf("-\tYou have entered food!\t\t\t\t\t\t -\n");
printf("\n");
}
else
{
printf("\tYou have entered an invalid choice!\n");
printf("\tPlease restart the program!\n");
printf("\n");
}
return 0;
}
void create_boxed_menu()
{
// Creating variables
int i;
printf("\n");
printf("- \t\tWelcome to the T.G.I. Friday's Menu Quiz! \t\t -\n");
for (i=0; i< 2; i++)
{
create_sides();
}
printf("- \tPlease select a category that you would like to be quizzed on: -\n");
create_sides();
printf("- \tFor drinks, type 1 and hit enter \t\t\t\t -\n");
printf("- \tFor food, type 2 and hit enter \t\t\t\t\t -\n");
for (i=0; i< 1; i++)
{
create_sides();
}
}
void create_top()
{
int i, width=75;
for (i=0; i< width; i++)
{
printf("-");
}
}
void create_bottom()
{
int i, width=75;
for (i=0; i< width; i++)
{
printf("-");
}
}
void create_sides()
{
printf("-\t\t\t\t\t\t\t\t\t -\n");
}
void drinks_was_selected()
{
int i;
char *drink_categories[7] = {"Wine", "Beer", "Crushes", "Slushes", "Shakers", "House Specialties", "Ultimates"};
printf("-\tPlease select from the following drinks:\t\t\t -\n");
create_sides();
// Loop beer and wine only so the dashes line up!
for (i=0; i<2; i++)
{
printf("-\t%d. %s\t\t\t\t\t\t\t\t -\n", i+1, drink_categories[i]);
}
// Loop Crushes through Shakers so the dashes line up!
for (i=2; i<5; i++)
{
printf("-\t%d. %s\t\t\t\t\t\t\t -\n", i+1, drink_categories[i]);
}
// Printing House Specialties
for (i=5; i<6; i++)
{
printf("-\t%d. %s\t\t\t\t\t\t -\n", i+1, drink_categories[i]);
}
// Printing Ultimates
for (i=6; i<7; i++)
{
printf("-\t%d. %s\t\t\t\t\t\t\t -\n", i+1, drink_categories[i]);
}
create_sides();
}
void wine_was_selected()
{
quiz* wine = malloc(sizeof(quiz));
int i, number_of_wine_questions;
number_of_wine_questions = 15;
// Create a temporary buffer array that holds the wine questions
char wine_questions[20][100] = {"Which wine has citrus combined with caramel and fresh baked shortbread?",
"Which wine has apples, lemon, pineapple and mango with honey and vanilla?",
"Which wine has honeyed peaches and apple flavor with a vanilla aroma?",
"Which wine has peach, apricot, and a hint of citrus?",
"Which wine has sweet passion fruit and sweet lime?",
"Which wine has red berry, citrus and melon, nutmeg and clove?",
"Which wine has a wild flower aroma with a tropical fruit flavor?",
"Which sparkling wine has an extremely delicate note?",
"Which wine has an aroma of cherries with red currants and spice?",
"Which wine has black cherry, cranberry with vanilla and oak?",
"Which wine has an aroma of dark cherry with clove and oak?",
"Which wine has blackberry, black cherry with black pepper?",
"Which wine has currant, raspberry, and blackberry with a vanilla finish?",
"Which wine has currants, berries and tannins in this wine?",
"Which wine has anise, mocha, dark berry, black cherry, spices, and chocolate?"};
for (i=0; i< number_of_wine_questions; i++)
{
strcpy(wine[i].question, wine_questions[i]);
printf("%s\n", wine[i].question);
}
}
Output:
Code:
menuquiz.c: In function ‘wine_was_selected’:
menuquiz.c:226:9: warning: passing argument 1 of ‘strcpy’ from incompatible pointer type [enabled by default]
/usr/include/string.h:128:14: note: expected ‘char * __restrict__’ but argument is of type ‘char (*)[100]’
menuquiz.c:227:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[100]’ [-Wformat]
---------------------------------------------------------------------------
- Welcome to the T.G.I. Friday's Menu Quiz! -
- -
- -
- Please select a category that you would like to be quizzed on: -
- -
- For drinks, type 1 and hit enter -
- For food, type 2 and hit enter -
- -
- -
- Your selection is: -
1
- -
- Please select from the following drinks: -
- -
- 1. Wine -
- 2. Beer -
- 3. Crushes -
- 4. Slushes -
- 5. Shakers -
- 6. House Specialties -
- 7. Ultimates -
- -
- Which category of drinks would you like to be quizzed on: -
1
Which wine has citrus combined with caramel and fresh baked shortbread?
Which wine has apples, lemon, pineapple and mango with honey and vanilla?
Which wine has honeyed peaches and apple flavor with a vanilla aroma?
Which wine has peach, apricot, and a hint of citrus?
Which wine has sweet passion fruit and sweet lime?
Which wine has red berry, citrus and melon, nutmeg and clove?
Which wine has a wild flower aroma with a tropical fruit flavor?
Which sparkling wine has an extremely delicate note?
Which wine has an aroma of cherries with red currants and spice?
Which wine has black cherry, cranberry with vanilla and oak?
Which wine has an aroma of dark cherry with clove and oak?
Which wine has blackberry, black cherry with black pepper?
Which wine has currant, raspberry, and blackberry with a vanilla finish?
Which wine has currants, berries and tannins in this wine?
Which wine has anise, mocha, dark berry, black cherry, spices, and chocolate?
- -
- -