For my C++ programming course, the prof wants us to do an order queuing program, however he hasn't taught queues and stacks yet. Is there a way I could use arrays (with dynamic memory allocation) to act as a queue? This is the
code I have so far, but I don't know where to start with the queue.
#include <stdio.h>
void Menu(void)
{
printf("I: Insert an item\n");
printf("P: Remove items from queue and process order\n");
printf("Q: Quit program\n");
}
char GetChoice(void)
{
char t;
scanf("%c",&t);
return t;
}
main()
{
float n;
int i;
int d,f;
char c;
float p;
Menu();
printf("Enter the letter for your choice:\n");
c = GetChoice();
while (c != 'Q')
{
if (c == 'I')
{
printf("Enter number of items to add into queue:\n");
scanf("%d",&i);
if(i<0)
{
printf("number is not valid");
return 0;
}
for(f=0;f<i;f++)
{printf("Enter the price of the item to insert into the queue:\n)";
scanf("%f", &n);
}
}
else if (c == 'P')
{
printf("How many items do you want to process");
scanf("%d",&i);
if(i<0)
{
printf("number is not valid");
return 0;
}
for(f=0;f<i;f++)
{
printf("Item cost is %f\n", n);
p += n;
}
printf("Total cost is %f\n",p);
}
}
else if (c != 'Q')
printf("Invalid Choice. You must use I, P, or Q.\n");
Menu();
printf("Enter the letter for your choice: ");
c = GetChoice();
};
return 0;
}