Struct Prob
-
I was reading about structers in Oriely's c++ and well unfortunately I couldnt buy the book, but I took photos with my phone and what I did what write my own code and i get no errors when I compile it. This is my code:
// Virtual Structure.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <conio.h>
using namespace std;struct Virtual_Bin{
int Type;
int Quantity;
double Price;
} Produce_Choice;int _tmain(int argc, _TCHAR* argv[])
{
double i;
Virtual_Bin Produce_Choice; //Produce - My virtual Bin stores information based on produce.cout << " Fruit Type: "; cin >> Produce\_Choice.Type; cout << "Fruit Amount: "; cin >> Produce\_Choice.Quantity; cout << " Fruit Price: "; cin >> Produce\_Choice.Price; cout << " Type: " << Produce\_Choice.Type << endl; cout << " Quantity: " << Produce\_Choice.Quantity << endl; cout << "Price Each: " << Produce\_Choice.Price << endl; i = Produce\_Choice.Quantity \* Produce\_Choice.Price; cout << "Total for quantity of " << Produce\_Choice.Quantity << ": " << i; \_getch(); return 0;
}
My Build:
------ Build started: Project: Virtual Structure, Configuration: Debug Win32 ------
Virtual Structure - up-to-date.
---------------------- Done ----------------------
Build: 1 succeeded, 0 failed, 0 skipped
My output on the screen is:
Fruit Type: Apple
Fruit Amount: Fruit Price: Type: -858993460
Quantity: -858993460
Price Each: -9.25596e+061
Total for quantity of -858993460: 7.95081e+070 -
I was reading about structers in Oriely's c++ and well unfortunately I couldnt buy the book, but I took photos with my phone and what I did what write my own code and i get no errors when I compile it. This is my code:
// Virtual Structure.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <conio.h>
using namespace std;struct Virtual_Bin{
int Type;
int Quantity;
double Price;
} Produce_Choice;int _tmain(int argc, _TCHAR* argv[])
{
double i;
Virtual_Bin Produce_Choice; //Produce - My virtual Bin stores information based on produce.cout << " Fruit Type: "; cin >> Produce\_Choice.Type; cout << "Fruit Amount: "; cin >> Produce\_Choice.Quantity; cout << " Fruit Price: "; cin >> Produce\_Choice.Price; cout << " Type: " << Produce\_Choice.Type << endl; cout << " Quantity: " << Produce\_Choice.Quantity << endl; cout << "Price Each: " << Produce\_Choice.Price << endl; i = Produce\_Choice.Quantity \* Produce\_Choice.Price; cout << "Total for quantity of " << Produce\_Choice.Quantity << ": " << i; \_getch(); return 0;
}
My Build:
------ Build started: Project: Virtual Structure, Configuration: Debug Win32 ------
Virtual Structure - up-to-date.
---------------------- Done ----------------------
Build: 1 succeeded, 0 failed, 0 skipped
My output on the screen is:
Fruit Type: Apple
Fruit Amount: Fruit Price: Type: -858993460
Quantity: -858993460
Price Each: -9.25596e+061
Total for quantity of -858993460: 7.95081e+070try change to this: typedef struct VIRTUAL_BIN { int Type; int Quantity; double Price; } Virtual_Bin;
-
try change to this: typedef struct VIRTUAL_BIN { int Type; int Quantity; double Price; } Virtual_Bin;