473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Logical Error: Help Pls.

can someone pls tell me why this thing would not calculate my division intergers and show it within my struct. PLS HELP I'M NEW TO C++, AND HAVE SPENT 4 DAYS TRYING TO FIND OUT WHY I CANT DO THIS THING RIGHT. I'M ACCTUALLY TRYING TO FIGURE OUT HOW STRUCTS WORK BUT IT SEEMS LIKE I CANT GET IT TO TOTAL MY INTERGER AND DISPLAY IT WHEN I CALL THEM IN MAIN.

THANKS


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. struct CorpData
  9. {
  10.     string DivisionName;
  11.     int FirstQtr;
  12.     int SecondQtr;
  13.     int ThirdQtr;
  14.     int FourthQtr;
  15.     int Total_An_Sales;
  16.     int Average_Qtr_Sales;
  17.  
  18.     CorpData(string n = "", int F1Qtr = 0, int S2Qtr = 0, int T3Qtr = 0, int F4Qtr = 0)
  19.     {
  20.         DivisionName = n;
  21.         FirstQtr = F1Qtr;
  22.         SecondQtr = S2Qtr;
  23.         ThirdQtr = T3Qtr;
  24.         FourthQtr = F4Qtr;
  25.     }
  26.  
  27. };
  28.  
  29.  
  30. CorpData DPY();
  31. CorpData Calc();
  32.  
  33. CorpData Calc()
  34. {
  35.     CorpData Math;
  36.     Math.Total_An_Sales = Math.FirstQtr + Math.SecondQtr + Math.ThirdQtr + Math.FourthQtr;
  37.     Math.Average_Qtr_Sales = Math.Total_An_Sales/4;
  38.     return Math;
  39. }
  40.  
  41.  
  42.  
  43.  
  44. CorpData DPY()
  45. {
  46.     CorpData Display;
  47.     cout <<"\n\nHere are the Quartely proceeds from Mike & Ike, by Divisions.\n\n" << endl;
  48.  
  49.     cout <<" DIVISION NAME : "<< Display.DivisionName << endl;
  50.     cout <<" FIRST QTR     : "<< Display.FirstQtr << endl;
  51.     cout <<" SECOND QTR    : "<< Display.SecondQtr << endl;
  52.     cout <<" THIRD QTR    : "<< Display.ThirdQtr << endl;
  53.     cout <<" FOURTH QTR  : "<< Display.FourthQtr << endl;
  54.     cout <<" TOTAL SALES : "<< Display.Total_An_Sales << endl;
  55.     cout <<" AVERAGE QTR SALES: "<< Display.Average_Qtr_Sales << endl;
  56.  
  57. return Display;
  58. }
  59.  
  60.  
  61. int main()
  62. {
  63. CorpData east("East", 16500, 25000, 10000, 18000);
  64. CorpData west("West", 25654, 15321, 13654, 25316);
  65. CorpData north("North", 32123, 41583, 10003, 21005);
  66. CorpData south("South", 20123, 30125, 10002, 14159);
  67.  
  68.     east = Calc();
  69.     west = Calc();
  70.     north = Calc();
  71.     south = Calc();
  72.  
  73.     east = DPY();
  74.     west = DPY();
  75.     north = DPY();
  76.     south = DPY();
  77.     return 0;
  78. }
Mar 11 '07 #1
1 1682
Banfa
9,065 Expert Mod 8TB
You do not pass any data to the functions for them to work on. For example in Calc no data to is passed to the function, the Calc function instantiates a CorpData structure internally, this calls the constructor and sets all the values to 0, it does the calculation on those 0 values and then passes the structure back as the return value where it over-writes the actual data in the top level structures.

I similar thing happens in DPY.

You need to pass the data into the function and work on the actually data not instantiate a new object internally to the function. You can either

pass the top level structures to the function using a pointer or reference.

make the functions members of the structure so that they can act directly on the structures data.

Which every you do there will be no need to pass the structure back to main as a return value.
Mar 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
7
by: Charles Crume | last post by:
Hello all; I have used dBASE, and other computer languages/databases, for years. They all have a logical field type. However, the version of MySQL used by the ISP hosting my site does not...
80
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one...
23
by: Cor | last post by:
Hi group, A question to the group, would it not be for a lot of the users better when there was beside "Option strict on" an "Option logical Strict on". I was automaticaly writting...
2
by: ThunderMusic | last post by:
Hi, I have a value that contains flags that I must get using a bitmask. I tryied with the && operator, but the compiler outputs this error : Operator '&&' cannot be applied to operands of type...
0
by: Roald | last post by:
I am working on an application that needs to implement logical deletes instead of removing the records permanently. The logical delete works by setting 3 fields (deleted flag, date and user). I...
14
by: blueboy | last post by:
Hi, I am planning to automate a nighty restore of a DB on another server can someone point me in the right direction with the SQL script to modify the logical file names to the correct path and...
11
by: Dominic Vella | last post by:
I am using MS-Access2000. I can't seem to set the default values for Logical type fields. I start with Dim dbsTmp As Object ' I think it's DAO.Database Set dbsTmp =...
7
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.