I think i made the structure right???, now I have to make it work with the functions....some by reference, some by value... the program works right without the structure (which gives me my first clue that something isn't right). Also how do you clear the screen? I tried clrscr(); and it didn't work. I am in MS Visual C++ console (2003). I'd appreciate any help....
Code:
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#using <mscorlib.dll>
using namespace std;
struct inventory
{
public:
char product;
int quantity;
};
void main_menu(char&, int&, float&);
void get_input(char&, int&, float&);
float calculate(char, int, float);
void update_info(char&, int&, float&);
int main()
{
inventory i1;
i1.product;
i1.quantity = 0;
float price, total;
char product;
int quantity;
main_menu(product, quantity, price);
return 0;
}
void main_menu(char&, int&, float&)
{
int numbinput, quantity;
float price, total;
char product;
do
{
cout << endl << "Enter a number: " << endl;
cout << "1. Enter Information" << endl;
cout << "2. Calculate Sales" << endl;
cout << "3. Update Informaton" << endl;
cout << "4. Exit" << endl << endl << endl;
cin >> numbinput;
switch (numbinput)
{
case 1:
{
get_input(product, quantity, price);
break;
}
case 2:
{
total = calculate(product, quantity, price);
cout << "Total: $" << total << endl;
cout << "Press the spacebar to continue...";
getch();
break;
}
case 3:
{
update_info(product, quantity, price);
break;
}
}
}
while (numbinput != 4);
}
void get_input(char& product, int& quantity, float& price)
{
cout << "Product Name: ";
cin >> product;
cout << "Quantity: ";
cin >> quantity;
cout << "Price: $";
cin >> price;
cout << "Press the spacebar to continue...";
getch();
}
float calculate (char product, int quantity, float price)
{
float total;
cout << "Product: " << product << endl;
cout << "Quantity: " << quantity << endl;
cout << "Price: " << price << endl;
total = price * quantity;
return total;
}
void update_info(char& product, int& quantity, float& price)
{
cout << "Product: " << product << endl;
cin >> product;
cout << "Quantity: "<< quantity << endl;
cin >> quantity;
cout << "Price: " << price << endl;
cin >> price;
cout << "Press the spacebar to continue...";
getch();
}