Msaada: Nashindwa kupata output katika code


thesym

thesym

JF-Expert Member
Joined
Aug 15, 2012
Messages
3,110
Points
2,000
thesym

thesym

JF-Expert Member
Joined Aug 15, 2012
3,110 2,000
nashindwa kupata output katika hii kodi kila nikirun output inafail.
Code:
#include<iostream>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
int main()
{ vector<vector <double> > mat; vector<double>meanvector; ifstream rea("read.txt"); string s; while(!rea.eof()) { rea>>s; vector<double>temp; double temp1; while(rea>>s && s!="#") { stringstream convert(s); convert>>temp1; temp.push_back(temp1); } if(!temp.empty()); mat.push_back(temp); } cout<<"Now the vector mean is:"<<endl; for(int i=0;i<mat[i].size();i++) { double sum=0; for(int u=0;u<mat.size();u++) { sum=sum+mat[u][i]; } for(int j=0;j<1;j++) { cout<<sum; } meanvector.push_back(sum/mat.size()); }
}
input data katika text file read.txt
D1 2 2 0 #

D2 2 3 5 #

D3 5 7 1 #

D4 5 7 1 #

D5 5 7 1 #
 
Root

Root

JF-Expert Member
Joined
Jan 23, 2012
Messages
29,919
Points
2,000
Root

Root

JF-Expert Member
Joined Jan 23, 2012
29,919 2,000
Je inaonesha error gani unapoirun.
 
thesym

thesym

JF-Expert Member
Joined
Aug 15, 2012
Messages
3,110
Points
2,000
thesym

thesym

JF-Expert Member
Joined Aug 15, 2012
3,110 2,000
console inarun baadae ina stop
 
Pancras Suday

Pancras Suday

Verified Member
Joined
Jun 24, 2011
Messages
7,731
Points
2,000
Pancras Suday

Pancras Suday

Verified Member
Joined Jun 24, 2011
7,731 2,000
console inarun baadae ina stop
Nimejaribu kupitia hio code, kama sikosei nimeona ni sehemu moja tu ambapo unaweza kutoa output zako kwenye console ambayo ni "cout<<"Now the vector mean is:"<<endl;" hii sehemu kama inatakiwa kutoa output atleast inatakiwa kuwepo return variable au call function lakini hakuna unless kwenye code zako kuna sehemu sijaiona
 
NullPointer

NullPointer

JF-Expert Member
Joined
Feb 7, 2011
Messages
3,479
Points
2,000
NullPointer

NullPointer

JF-Expert Member
Joined Feb 7, 2011
3,479 2,000
nashindwa kupata output katika hii kodi kila nikirun output inafail.
Mkuu umejaribu kufanya debugging kwanza kwa kucheki kama inasoma file lenyewe?? I mean kwanza uangalie kama code yako inafika kwenye hiyo while loop ya kwanza unaweza kujaribu kwa "cout" kucheki kama imefika, then udebug kucheki kama imesoma file lenyewe kwa kuprint out content ya file wakati inalisoma....

Alafu another thing, hiyo for loop yako ya kuprint out sum, kwa nini unatumia loop huku you are not even looping?? "for (int j=0; j<1; j++)" just print out the sum bila kuiweka ndani ya loop
 

Forum statistics

Threads 1,285,389
Members 494,586
Posts 30,860,211
Top