School project (I'm doomed)

I have a school project that I need to turn in on ot the 12th of Octomber (in 12 days). Since I've never touched a program in my life, 12 days seems like a small time for me to brainstorm.... So I come here for help. The task is the following:
Write a program to keep a list of available items in a sports goods store. For each item, the following information must be stored: Name, Manufacturer, Price, Available items. The program should support the following features, as a text menu from which the user can choose:
• Enter a new item in the list
• Search by Manufacturer of an item
• Sort items in the list by Name
• Display the current content of the list
This is what I wrote so far:

#include "pch.h"
#include <iostream>
#include <conio.h>
#include <string.h>
#include <dos.h>

using namespace std;

typedef struct
{
char name[20];
char manufacturer[15];
double price;
char available;
} articles;




int main()
{
int choice;

do
{
cout << ("\n ##################################################");
cout << ("\n # Menu #");
cout << ("\n # 1.Enter new article #");
cout << ("\n # 2.List of manufacturers of articles #");
cout << ("\n # 3.Sort articles by name #");
cout << ("\n # 4.Display the current content of the list #");
cout << ("\n ##################################################") << endl;
cin >> choice;

switch (choice)
{
case 1:
articles artic { };
cout << ("Enter a name: ");
cin >> (artic.name);
fflush(stdin);
return(artic);
break;
}

/*
After this I'm getting a C2440 Error which I can't wrap my head around. I'd use any info on why this might be happening, and I could also use some tips on how to make this program be efficient. I have an idea on how to output the list of manufacturers, but thats basically it. Also I didn't write all the couts and cins for the structure, this is just an example. Thanks in advance.
Last edited on
I can't read your monitor from where I'm sitting. Perhaps you can tell us the complete error message, including the information it contains about the line of code it objects to.
I managed to fix the C2440 error by replacing return(artic); with cout << artic.name;. So that problem has been fixed. What I can use is some example codes for the other options, selected from the menu :)
You haven't finished option one yet.

This is C code:
1
2
3
4
5
6
7
typedef struct
{
char name[20];
char manufacturer[15];
double price;
char available;
} articles;


You're meant to be writing in C++:
1
2
3
4
5
6
7
struct article
{
string name;
string manufacturer;
double price;
bool available;
};



These are all something you shouldn't using:
1
2
3
#include <conio.h>
#include <string.h>
#include <dos.h> 
Last edited on
#include "pch.h"
#include <iostream>
#include <conio.h>
#include <string.h>
#include <dos.h>

using namespace std;

struct articles
{
char name[20];
char manufacturer[15];
double price;
char available;
};



int main()
{
int choice;

do
{
cout << ("\n ##################################################");
cout << ("\n # Menu #");
cout << ("\n # 1.Enter new article #");
cout << ("\n # 2.List of manufacturers of articles #");
cout << ("\n # 3.Sort articles by name #");
cout << ("\n # 4.Display the current content of the list #");
cout << ("\n # 5. End of program #");
cout << ("\n ##################################################") << endl;
cin >> choice;

switch (choice)
{
case 1:
articles newart { };
cout << ("Enter a name: ");
cin >> (newart.name);
cout << ("Enter a manufacturer: ");
cin >> (newart.manufacturer);
cout << ("Enter a price: ");
cin >> (newart.price);
cout << ("Enter if its available (y/n): ");
cin >> (newart.available);
fflush(stdin);
cout << ("The new article you've created is the following: \n");
cout << newart.name << endl;
cout << newart.manufacturer << endl;
cout << newart.price << endl;
cout << newart.available << endl;
break;
}

this is where I'm at right now. It works fine this way and it lets the user input a new article. If I do what you said @Repeater, and change the char to string and bool, it screws up my program and gives me errors for all the couts..... Any Idea?>
gives me errors for all the couts..... Any Idea?>

Yes. Fix the errors.

I would tell you more but YOU STILL AREN'T TELLING US WHAT THE ERRORS ARE.

Seriously, we're not psychic. You have to tell us what the errors are. Help us. Help us to help you. Just standing there saying "it doesn't work there is an error" isn't enough information.

If you want to use string, you have to #include <string>

Your program needs to be able to store more than one article. Make it store more than one article. Make it able to store five. Make it able to store ten. Make it able to store thousands.
Last edited on
first, i'm sorry because i'm totally noob.
but, maybe, you could:
struct articles
{
char name[20];
char manufacturer[15];
double price;
char available;
}articles[5];

so you can enter different articles.
and a counter for each article.
like:

int numberArticles = 0;
when you enter a new article:
article[numberArticles];
// after you complete all the fields//
numberArticles++;

i hope you can understand me and again, sorry for my bad bad english.

Topic archived. No new replies allowed.