Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Struct Prob

Struct Prob

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginglearningworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Herboren
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • H Herboren

      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

      T Offline
      T Offline
      tibiz
      wrote on last edited by
      #2

      try change to this: typedef struct VIRTUAL_BIN { int Type; int Quantity; double Price; } Virtual_Bin;

      tibiZ.net homepage

      H 1 Reply Last reply
      0
      • T tibiz

        try change to this: typedef struct VIRTUAL_BIN { int Type; int Quantity; double Price; } Virtual_Bin;

        tibiZ.net homepage

        H Offline
        H Offline
        Herboren
        wrote on last edited by
        #3

        Nevermind I figured it out, my:

        struct VIRTUAL_BIN{
        char Type[32]; <--- was of 'type' int, when it was supposed to be 'char'
        int Quantity;
        float Price;
        } Produce_Choice;

        modified on Monday, March 8, 2010 9:50 PM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups