-
Help in some errors!!!!!
Code:
1>------ Build started: Project: h, Configuration: Debug Win32 ------
1>Compiling...
1>h2.cpp
1>c:\users\alsaadi\documents\visual studio 2008\projects\h\h\h2.cpp(21) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\alsaadi\documents\visual studio 2008\projects\h\h\h2.cpp(33) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\alsaadi\documents\visual studio 2008\projects\h\h\h2.cpp(36) : error C2446: '==' : no conversion from 'int' to 'int *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\alsaadi\documents\visual studio 2008\projects\h\h\h2.cpp(36) : error C2040: '==' : 'int [11]' differs in levels of indirection from 'int'
1>Build log was saved at "file://c:\Users\ALSAADI\Documents\Visual Studio 2008\Projects\h\h\Debug\BuildLog.htm"
1>h - 2 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Code:
This my programme:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main ()
{
ofstream MyOutFile;
int sum1;
int prod1;
int sum2;
int prod2;
int sumR;
int prodR;
int A[11];
int RandomNamber1; srand (time(0));
RandomNamber1 = rand();
if (A==0,2,4,6,8,10)
sum1=0+2+4+6+8+10;
else
prod1=0*2*4*6*8*10;
int B[11];
int RandomNamber2;
srand (time(0));
RandomNamber2 = rand();
if (A==1,3,5,7,9,11)
sum2=1+3+5+7+9+11;
else
prod2=1*3*5*7*9*11;
int Result[11];
sumR=sum1+sum2;
prodR=prod1*prod2;
MyOutFile.open ("MyData.txt");
int OF;
MyOutFile << endl;
MyOutFile <<"------------------------------------------";
MyOutFile << "Array 1:" << setw(5) << Result << endl;
MyOutFile <<"------------------------------------------";
MyOutFile << "Array 2:" << setw(5) << Result << endl;
MyOutFile <<"------------------------------------------";
MyOutFile << "Result:" << setw(5) << Result << endl;
MyOutFile <<"------------------------------------------";
MyOutFile.close();
return 0;
}
-
> if (A==1,3,5,7,9,11)
This is not how you compare the contents of an array with a list of numbers.
Use a for loop of some sort.
> srand (time(0));
Try
srand ((unsigned int)time(0));
to fix the "loss of precision" warnings.