Urgent ArchWindow

Alright my problem with my code is no matter what I do it keeps giving me numbers way off. I know that the main issue is my setData but I really don't know what I am doing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <ctype.h>
#include "Arch_Rect_Win.h"

using namespace std;

class Arch_Rect_Win
{
    private:
    	int Width, Height;
        double pi, p, TotalArea, PricePSqIn;
        char ArchOrRect;
        
    public:
        Arch_Rect_Win();
		double getHeight() const;
        double getWidth() const;
        double getArea();
        double getPrice() const;
        double getPricePSqIn() const;
        char getRectOrArch() const;
        int setData(char *, char *, char *, char );
};
int main()
{
	Arch_Rect_Win aWin;
	char h[10], w[10],p[10];
	char rORa;
	int validData;
	int Height = 0;
	int Width = 0;
    int PricePSqIn = 0;
		
		do
		{
			cout << "\n\t Enter Window Height: ";
			cin >> h;
			cout << "\t Enter Window Width: ";
			cin >> w;
			cout << "\t Enter Price Per Sq in: ";
			cin >> p;
			cout << "\t Enter ""A"" for Arch, ""R"" for Rectangle: ";
			cin >> rORa;
			validData = aWin.setData(h,w,p, rORa);
			if (validData == 0)
			{
				cout << "\n\n\tError in Data!";
				cout << "\n\t\tMust enter either ""A"" for Arch or ""R"" for Rect";
				cout <<"\n\t\tIf Arch Window, height must be >= half of the width for arch window\n";
				
			}
			
		} while (validData == 0);
	
system("CLS");
if (aWin.getRectOrArch() == 'A')
	cout << "\n\t\t* * * Arch Window * * *\n";
else
	cout <<"\n\t\t\t * * * Rectangle Window * * *\n";
	
cout << setiosflags (ios::showpoint | ios::fixed) << setprecision(2);
cout <<"\n\t				Height: " << aWin.getHeight();
cout <<"\n\t				Width: " << aWin.getWidth();
cout <<"\n\tPrice Per Sq. In.: " << aWin.getPricePSqIn();
cout <<"\n\t				Total Area: " << aWin.getArea();
cout <<"\n\t				Total Price: " << aWin.getPrice();
getch();
}



Arch_Rect_Win::Arch_Rect_Win()
{
        pi = 3.14159;
}

double Arch_Rect_Win::getHeight() const
{
    return Height;
}

double Arch_Rect_Win::getWidth() const
{
    return Width;
}

double Arch_Rect_Win::getPricePSqIn() const
{
    return p;
}

char Arch_Rect_Win::getRectOrArch() const
{
	return ArchOrRect;
}

double Arch_Rect_Win::getArea()
{
	if(ArchOrRect == 'A')
	{
	   double radius = Width*.5;
    double AreaofArch = (pow(radius, 2.0) *  pi)/2;
    double AreaofRectangle = (Height - radius) *Width;
    TotalArea = AreaofRectangle + AreaofArch;
    return TotalArea;
	
	}
	else
	{
	double AreaofRectangle = Height * Width;
	TotalArea = AreaofRectangle;
	return TotalArea;	
 
	}
}

double Arch_Rect_Win::getPrice() const
{

    return p * TotalArea;
}

int Arch_Rect_Win::setData(char *h, char *w, char *p, char AorR)
{
	char buffer[256];
	*h = atoi (buffer);
	*w = atoi (buffer);
 	*p = atoi (buffer);
 
 
 
return 0;		



		
}



Last edited on
closed account (Dy7SLyTq)
how did you get away with no closing }; on your class?
I didn't I just missed the symbol when I copied and pasted. My original code is broken up into three files.
Last edited on
Also My other issue is when I type a for archwindow it takes you to rectangle window.
closed account (Dy7SLyTq)
well how is it breaking out of the while loop when setData returns nothing?
....That's kind of my question. What is setData supposed to return?
Last edited on
closed account (Dy7SLyTq)
at somepoint a zero
Are you sure? I tried returning a zero and it didn't help at all. I'll try again and post my results if anything changes.
Nothing I tried seemed to work. Do you know where I can find an example?
closed account (Dy7SLyTq)
No... return 0 or 1 not true or false
I tried returning 0 and nothing changed.
> it keeps giving me zero in my output. Why is that?
When you construct your window you set the Height and Width to 0.
Those values are never changed later, ¿so what did you expect?
closed account (Dy7SLyTq)
sorry my mistake change it to one. i was thinking it broke out once the condition was met for somereason

* * * Rectangle Window * * *

Height: 4200507.00
Width: 2293384.00
Price Per Sq. In.: 0.00
Total Area: -236099240.00
Total Price: -0.00



That is the output when I don't initialize it.
I changed it to 1 and it still did not change anything. What else could be wrong with it? I can't seem to figure it out.
Last edited on
I finally got numbers to appear but their way of.
> That is the output when I don't initialize it.
¿what do you expect if you are using uninitialized data?
I'm saying that you need to set it to a meaningful value.
Maybe `setData()' should set your members, ¿don't you think?
No that's not what I ment. the Height=0 and Width=0 was initialized. When I took that out my code kept giving me random garbage.
I know that setData() is supposed to set my members ,but I have tried many things and now I'm just lost on what I need to do.
Topic archived. No new replies allowed.