Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
//This program is to Place the order of the number of items that you would like to rent for a special occasion
#include<stdio.h>

#include<stdlib.h>

#include <string.h>

#include <conio.h>

//Declaration Of Constants
int notents;
int nochairs;
int nostables;
int noltables;
//Struct
struct order {
    int numTents;
    int numChairs;
    int numSTables;
    int numLTables;
    int Orderdays;
    int Ordermonths;
    int CustomerID;
    double Totaldue;
    };
//Integer variables used in program
int numorder, choice, x = 0;

//Declaration of Functions
void menu();
void logo();
void order();
void exit();

struct order All[15];

int main(){
	logo();
    menu();
    return 0;
}


void logo(){
	printf("Welcome to Wendell`s T.T.C\n");
    printf("****************************\n");
}

void menu(){
    printf("Please choose an Option?\n");
    printf("1. Place an Order\n");
    printf("2. Exit\n");
    scanf("%d", & choice);
    switch (choice) {
    case 1:
        order();
        break;
    case 2:
        printf("Exiting");
        exit();
        break;

    default:
        printf("Invalid choice, Please try again\n ");
        menu();
        break;

    }
}

void order() {
	FILE * pt = fopen("NoItems.txt", "a+");
	printf("Price for Tents $100\n");
    printf("Price for Chairs $15\n");
    printf("Price for SmallTables $25\n");
    printf("Price for LargeTables $50\n\n");
    printf("How many orders would you like to place\n");
    scanf("%d", &numorder);
    int i;
    for (int i=1; i<=numorder; i++) {
    	printf("Current Order %d\n", i);
        printf("Number of Tents\t");
        scanf("%d",&All[i].numTents);
        printf("Number of Chairs\t");
        scanf("%d", &All[i].numChairs);
        printf("Number of Small tables\t");
        scanf("%d", &All[i].numSTables);
        printf("Number of large tables\t");
        scanf("%d", &All[i].numLTables);
        printf("Order month\t");
        scanf("%d", &All[i].Ordermonths);
        printf("Order day\t");
        scanf("%d", &All[i].Orderdays);
        All[i].Totaldue = (All[i].numTents * 100) + (All[i].numChairs * 15) + (All[i].numSTables * 25) + (All[i].numLTables * 50);
        printf("Total Due $%.2f \n",All[i].Totaldue);
		        fprintf(pt, "\n%d %d %d %d %d %d %lf ", All[i].numTents, All[i].numChairs, All[i].numSTables, All[i].numLTables, All[i].Orderdays, All[i].Ordermonths, All[i].Totaldue);
    
	//Closing  for loop
	}
    fclose(pt);
    menu();
}


void exit(){
	exit(0);
};


What I have tried:

The linear search I entered has errors
Posted
Updated 22-Feb-22 5:48am
Comments
k5054 15-Jan-22 22:54pm    
I see no attempt at a linear search here. But unless you're required to write a linear search as part of your homework, then you should probably use the library standard lsearch() (or _lsearch() or _lsearch_s() depending on your compiler environment) routine.
Michael Joseph Apr2021 15-Jan-22 23:29pm    
its for a project where exactly I'm inputting this search
Richard MacCutchan 16-Jan-22 2:56am    
You need to add a login function which gets called before any other. That can them check if the customer name exists, or if you need to add a new one to your database.

There is no linear search in there, either explicit via a loop, or implicit via library code.

Start by going back to your assignment and reading it carefully - generally the instructions are pretty explicit as to what exactly is required of you. Then read your notes from the last lecture (or two) in the light of your new understanding of the task and you should have a good idea what to do.
If you have tried to search but it "has errors" then show use exactly what the code you tried was, and explain what it did that you didn't expect, or didn't do that you did. Show us any error messages, and where they occur. Explain how you got them to happen, and what you have tried to do to fix them.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Quiet simple you only need somewhere the name information like in the order struct and than some iteration and usage of strcmp.

In a real world scenario you would have a user database which provides unique id for a user which than would be used with the order.

C++
int getUserId(char* fullName, char *email, ...);//search in db OR creates new
struct UserData getUserData(int id);// all data which belongs to the user like names, email, address, payment and so on

struct order {
    int userID; // used here
    int numTents;
 
Share this answer
 
Hello,
For such cases,
Sol.1
I strictly suggest think about database logic. Try to find select a desktop based database engine driver which it has own ODBC, ADA, OLe DB database engine driver. That database may be free of charge and has 3rd party database engine driver compatible with operating system in which database will operate. This is the easiest way to that and standart way using some transactions for SQL.
Sol. 2
Otherway is natural way you will use very well organized file content structure. That structure will have records. There must be primary key to locate spesific records. Since developer knows structure of file records (type of each column variable int, char string, double...etc) you will read each record and actual record must be parsed into columns (ie variables) and you will run your query -logic of decision) to see if it is your record or not. do it till you reach EOF (end of file) if there is no any record which satisfy your decision logic -query statement) then develope your action - add record - or just say "No any record for such a criteria-. Update, Delete, Add, ... diffrent actions might be devoloped by programmer. In this case more than one file, can be used and would be helpfull it is up to aim of customer needs. All of this stuff is naturally and easily can be done in first solution. Purpose of database is give service in safe, standart,... .

I hope this helps.

Regards,
IM
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900