Program not running properly ... i think

Hey, I wrote this program with the help of a few people. I build the program and I get 3 warnings and no errors. All of the read "warning C4305: 'argument' truncation from double to float. When I run the program and the black screen thing pops up, it shows nothing, just the blinking white thing at the top. I'm thinking it may be my computer and not the program but at the same time it works for everything else just not this one. So I'm thinking it may be the program or it is the computer that I'm using. Can anyone help me out, perhaps tell me if there is something wrong with my program that is causing it to just sit there without outputting anything. Thanks for the help.

Salesrecord.h

class SalesRecord
{
private:
float *sales_amount;
int number_of_sales;

public:
SalesRecord(int howmanysales);
SalesRecord( const SalesRecord& othersales );
~SalesRecord();
SalesRecord& operator= ( const SalesRecord& othersales ) ;
void StoreSale(float newsales, int index);
float FindSale(int index);


};

Main.cpp (According to the compiler, this is where my problem lies yet everything looks good to me. Would this cause the program to not work at all?)

#include<iostream>
#include "salesrecord.h"
using namespace std;
int main( )
{
SalesRecord s1(4), s2(3);
s1.StoreSale(2.4, 0); s1.StoreSale(8.7, 1);
s1.StoreSale(6.3, 2); s1.StoreSale(3.5, 3);
s2=s1;
s1.StoreSale(3.5, 0);
cout << s2.FindSale(0)<<endl;
cout << s2.FindSale(1)<<endl;
cout << s2.FindSale(2)<<endl;
cout << s2.FindSale(3)<<endl;
}

Salesrecord.cpp

#include<iostream>
#include "salesrecord.h"
using namespace std;

SalesRecord::SalesRecord(int howmanysales)
{
int i;
if (howmanysales<1)
{
cerr << "invalid size: ";
exit(1);
}
sales_amount=new float[howmanysales];
int number_of_sales=howmanysales;

for (i=0; i<number_of_sales; i++)
{
sales_amount[i]=0;
}
}
SalesRecord::SalesRecord( const SalesRecord& othersales )
{
number_of_sales = othersales.number_of_sales ;


sales_amount = new float[number_of_sales] ;
for( int i=0 ; i<number_of_sales ; ++i )
sales_amount[i] = othersales.sales_amount[i] ;
}


SalesRecord::~SalesRecord()
{
delete[] sales_amount;
}


void SalesRecord::StoreSale(float newsales, int index)
{
sales_amount[index]=newsales;
}

float SalesRecord::FindSale(int index)
{
return sales_amount[index];
}
SalesRecord& SalesRecord::operator= ( const SalesRecord& othersales )
{

if( sales_amount != othersales.sales_amount )
{
delete [] sales_amount ;

sales_amount = new float[number_of_sales] ;
for( int i=0 ; i<number_of_sales ; ++i )
sales_amount[i] = othersales.sales_amount[i] ;
}
return *this;
}

Please use code tags!

From what i see from your error, somewhere in the code you're converting a double to a float, which will knock off some decimal places and make the value less accurate. its commonly better to just use the same type so the compiler does no need to modify and change types when compiling in situations.
Last edited on
Sorry I'm quite new at this. I'll keep that in mind when I do this again. Would this cause the program to do nothing? Like its just a black screen with like a white line blinking on and off. I've never had that happen to me before now but I'm not sure if it is my program or not.
Topic archived. No new replies allowed.