i need a little help

i have a project where i have to use several IF statements without making them nested(without using "else")
the program should asks the user to enter a file size and accepts it in float where the program should calculate the time needed to transfer the file in days,hours,minutes and seconds where the speed is 960 bytes / second.
if the file takes more than one day to be transmitted the program should display a message asking the user to reduce the file size and should charge 1$ for each 5 mins if the file takes less than one day. If the transfer takes less than 5 minutes it should display that its free of charge.

Problem: the program should only display FREE OF CHARGE if the time is less than 5 minutes. but i am getting both.

My program is as follows :


#include <iostream.h>

int main()
{
    float file1;       // file1 represents the file size in MB
	cout << "Welcome\n\n";          //a welcome message


	cout<< "Please enter the file size to be transmitted in MB:"     //the program asks the user to enter the appropriate file size in MB
		<<endl;
         
   
	cin >> file1;             //the program places the number entered by the user in file1
   
   int day,hr,min,sec,min1,sec1,hr1;                //declaring variables        
   
	   sec1 = file1 / 0.00091545;                   /* sec1 is the total number of seconds     0.00091545 MB = 960 bytes (rounded value)
                                                       0.00091545 -------> 1sec
													   file1      -------> sec1?
                                                       sec1 =file1/0.00091545 */ 
	   min1 = sec1 / 60;                            //min1 is the total number of minutes      1 min = 60 sec

	   hr1 = sec1 / 3600;                           //hr1 is the total number of hours         1 hour = 3600 sec

	   day = sec1 / 86400;                          //day is the total number of days           day = 86400 sec

       min = min1 - (hr1*60);                       //min is the number of minutes the program should display... 
	   
	   sec = sec1 - ((hr1*3600)+(min*60));          //sec is the number of seconds the program should display

	   hr = hr1 - (day*24);                         //hr is the number of hours the program should display
	   
	cout <<"\n\n The time needed to transfer the file is:\n";   //a message that indicates the time needed to transfer the file


    
	
	cout <<day<<"(days)    "<<hr<<"(hours)    "<<min<<"(minutes)    "<<sec<<"(seconds)    \n\n\n\n";  //the time output

	if(day >= 1)          //the condition needed
		cout <<"Please reduce the file size"<<endl;   

	if(day<1)            //the condition needed
	cout<<"The cost of transmission is:"<<min1/5<<endl;    /*  5min ------> 1$
                                                               min1 -------> ??
															   cost=min1/5    */
	
   if(min1<5)
  
   cout<<"Free Of Charge"<<endl;
		
	
        

	

	return 0;
}


What do you think i should do ?
Thank you in return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#include <iostream>

using namespace std;

int main()
{
  float file_size = 0.0, total_cost = 0.0;
  cout << "Welcome" << endl << endl;
  cout<< "Please enter the file size to be transmitted in MB: ";
  cin >> file_size;
  cout << endl;

  int days = 0,hours = 0,mins = 0,secs = 0, total_secs = 0;

  total_secs = file_size / 0.00096;
  days = total_secs / 86400;
  if(days)
  {
    cout << "The time needed to transfer the file is more than one day!" << endl;
    cout << "Please reducte the file size" << endl;
    return 0;
  }
  hours = total_secs / 3600;
  mins = (total_secs - (hours * 3600)) / 60;
  secs = total_secs - (hours * 3600) - (mins * 60);
	cout << endl << endl << "The time needed to transfer the file is: " << endl;
  cout << hours << " hours" << endl;
  cout << mins << " minutes" << endl;
  cout << secs << " seconds" << endl << endl;
  cout << "The cost of transmission is: ";
  if(mins < 5)
  {
    cout << "Free Of Charge" << endl;
    return 0;
  }
  cout << "$" << cout.precision(2) << (float(total_secs) / 18000) << endl;
  return 0;
}
Last edited on
Thank you that was very helpful
Topic archived. No new replies allowed.