Data Structures and Algorithms Discussion Board
February 04, 2012, 09:28:32 AM *
Welcome, Guest. Please login or register.
Login with username, password and session length
News: Looking for a reliable webhosting provider? Read HostGator review to find 7 arguments in support of HostGator.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Help!!!  (Read 3156 times)
*Pali*
Guest
« on: February 19, 2009, 08:22:39 AM »

Hi!!
i'm trying to write a program that asks a clerk how many customers they served today, how many full hours they worked today, and how many additional minutes they worked today (if minutes are greater than or equal to 30, add an additional hour to time worked). then i want it to
Calculate the number of customers per hour served and  Output that average to a single decimal place to the screen with some useful message.

This is the code, but it's not working !!!
i'm doing something wrong but dont know where is it,

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   
    float customers,hours,minutes;
    double average;
    cout << " How many customers you served today? ";
    cin >> customers;
    cout << " How many full hours you worked today? ";
    cin >> hours;
    cout << " How many additional minutes you worked today? ";
    cin >> minutes;
   
    if(minutes >= 30)
    hours == hours +1;
    else
    minutes == minutes;

   average=customers / hours;
   cout << "You have served" << average << "customers per hour";
   
   system("PAUSE");
   return EXIT_SUCCESS;
}
Logged
Denis
Newbie
*

Rating: 0
Offline Offline

Posts: 21


« Reply #1 on: February 19, 2009, 01:56:06 PM »

Does it compile?

I fixed several errors, try new version:

Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

double customers, hours, minutes;
double average;
cout << " How many customers you served today? ";
cin >> customers;
cout << " How many full hours you worked today? ";
cin >> hours;
cout << " How many additional minutes you worked today? ";
cin >> minutes;

if(minutes >= 30)
hours++;

average=customers / hours;
cout << "You have served " << average << " customers per hour" << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

  • better not to mix floats and doubles
  • hours == hours + 1 doesn't increment hours, use hours = hours + 1 or, better, hours++
  • else block is not essential in current situation
Logged
*Pali*
Guest
« Reply #2 on: February 19, 2009, 10:55:02 PM »

Thanks Denis Smiley
Logged
Pages: [1]
  Print  
 
Jump to: