C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 10th, 2004, 10:55 PM
loopy123 loopy123 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 13 loopy123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wierd problem!

Hey all, I ran the code below , and it works just fine till the very end where dos says "hit any key to exit" (something like that).
THEN IT CRASHES MY COMPUTER!!!!!!!! I can't find the problem in it, though I suspect it's a pointer problem. Can someone please help me out! [the purpose of the program is to make the vector dot product, if some1 wants to see if the calculations are correct also, I would be pleased and grateful]
**THis program seems to only crash WIN ME in a blue screen way, other windows versions make the program disappear

#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <fstream>
//ALLOCATE MEMORY
using namespace std;
//starting code for hwc
struct vector {int dimen;
double *x, mag;};
void loadvec(vector &vec) //use cin to read vector data
{
//ask user for dimension and vector elements
cout << "Enter vector dim: ";
cin >> vec.dimen;
cout<<"\nEnter Vector elements:";
double temp=0;
for(int i=0;i<vec.dimen;i++){
cin>>vec.x[i];
temp=(temp+(vec.x[i]*vec.x[i]));}
vec.mag=sqrt(temp);
//calculate the magnitude of the vector here too, sqrt of sum of sqrs
}
double dotprod(vector vec1, vector vec2)
{//right by other
double dp = 0;
for (int i =0; i < vec1.dimen; i++)
dp = dp + vec1.x[i]*vec2.x[i];
//calculate the dot product
return dp;
}
void vecprint(vector vec)
{
for (int i = 0; i < vec.dimen; i++)
cout << vec.x[i] << endl;
}
int main(int argc, char *argv[])
{vector vec1,vec2;
//ask user for 2 vectors using loadvec
loadvec(vec1);loadvec(vec2);
//print out dot product and magnitude of each vector
cout << "Input vectors are :\n";
vecprint(vec1);
cout <<"and \n";
vecprint(vec2);
cout << "Magnitude is: vec1:"<<vec1.mag<<" vec2:"<<vec2.mag<<endl;
cout<< "The dot product = " << dotprod(vec1, vec2) << endl;
//be sure to delete allocated memory
//delete......
//Also, write the results to a file given on the command line.
//ofstream outfile(agrv[1]);

system("PAUSE");
return 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Wierd problem!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT