-
What am I doing wrong?
Okay, so I haven't touched c++ in a while (I wasn't that good to begin with either)...my program is as follows:
Code:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
double q,w;//boundary conditions
q =0.0;
w =8.0;
double a[7];//array where values are stored
int u = 0;
cout<<setprecision(2)<<setiosflags(ios::fixed)<<q<<" ";
double x = 1.0;
for(int f = 0; f < 7; f++)
{
double e = 1.0/8.0;
double g;
double v;
double c;
g = x*e;
v = 16-x;
c = g*v;
a[u] = c;//finds initial conditions
u++;
x++;
cout<<setprecision(2)<<setiosflags(ios::fixed)<<c<<" ";
}
cout<<setprecision(2)<<setiosflags(ios::fixed)<<w<<endl;
for(int i = 0; i < 20; i++)//20 lines of steps
{
cout<<setprecision(2)<<setiosflags(ios::fixed)<<q<<" ";
int z = 0;
for(int t = 0; t<7; t++)
{
double l;
int y = 0;
int p = 1;
int m = 2;
if(z == 0)//for initial corner of delta x
{
l = (a[0]/2.0)+(a[1]/4.0);
cout<<setprecision(2)<<setiosflags(ios::fixed)<<l<<" ";
z++;
}
else if(z < 6)//for middle terms of delta x
{
double j;
j = (a[y]/4.0)+(a[p]/2.0)+(a[m]/4.0);
cout<<setprecision(2)<<setiosflags(ios::fixed)<<j<<" ";
a[p] = j;
z++;
y++;//moves to the next numbers in the array
p++;
m++;
}
else if(z == 6)//for ending points of delta x
{
double b;
b = (a[5]/4.0)+(a[6]/2.0)+(w/4.0);
cout<<setprecision(2)<<setiosflags(ios::fixed)<<b<<" ";
a[6] = b;
z++;
}
a[0] =l;//to get the first changed number
}
cout<<setprecision(2)<<setiosflags(ios::fixed)<<w<<endl;
}
return 0;
}
This is an assignment of mine...the instructions were to write a program to solve the heat equation. Boundary conditions are 0 <= t <= 5, 0 <= x <= 8, and u(0,t)=0, u(8,t) = 8, s = 1/4
Initial condition is u(x,0) = (1/8)*x*(16-x)
The program should print out 20 t-steps, or lines, with accuracy to 2 decimals. At this point my program isn't even printing anything out, so I don't even know if the program itself is messed up or not.
Any help is greatly appreciated.
Last edited by Hack; 11-12-2007 at 11:49 AM.
Reason: Added Code Tags
-
I think you just need a "pause" before the dos-console gone away...
before "return 0;" put anything that hold the black screen for some time ...
maybe system("PAUSE"); >>>u need include<windows.h>
or maybe a getch(); >>> u need include<conio.h>
or just use any of your variables:
cin>>q;
hope this can helps.
-
Welcome to DevX :WAVE:
I edited your post and added [code]your code goes here[/code] tags to what you posted. As you can see, using the tags make it much easier to read and follow.
Thanks and once again, welcome aboard. :)
Similar Threads
-
By asdrukken in forum VB Classic
Replies: 5
Last Post: 07-07-2007, 09:33 PM
-
Replies: 1
Last Post: 12-20-2005, 03:50 AM
-
By Shilpa in forum VB Classic
Replies: 0
Last Post: 12-13-2005, 03:59 AM
-
By Alan Bell in forum .NET
Replies: 1
Last Post: 04-01-2002, 11:02 PM
-
By Richard Kalis in forum VB Classic
Replies: 1
Last Post: 03-20-2002, 12:31 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|