Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-03-2005, 05:57 AM   #1 (permalink)
Aznxmel
Registered User
 
Join Date: Mar 2005
Posts: 3
Aznxmel is on a distinguished road
Unhappy Bill Calculation

Im a newbie as everyone knows. and im stressing this project. here it is

i know i have to use if and else statements with this problem

It is a cell phone bill calculation:

I'm soppouse to write a progam that calculates a bill. there are two types of services Regular and Premium. The program needs a service code(type char) a service code of P means Premium service and R for Regular service.

Regular services: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute.
Premium service: $25.00 plus:
a. For calls made from 6:00 a.m. to 6:00 p.m., the first 75 minutes are free; charges for over 75 minutes are $0.10 per minutes
b. For calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for over 100 minutes are $0.05 per minute.
Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used. A service code of r or R means regular service; a service code of p or P means premium service. Treat any other character as an error. Your program should output the account number, type of service, number of minutes the telephone service was used. And the amount due from the user.
For the premium service, the customer may be using the service during the day and the night. Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes the service was used during the night.


so i typed

double accountNumber (0.0);
double numberOfMinutes (0.0);
char service code

how do i add the P and R to the code to recognize it is a sercice code.

it alsy says that the premiumservice, the customer may be using the service code

now the if and else staments i typed for Regular

if (X < 50): $10.00
else .20 per minute;

Now for Preium:

i dont know how to write this one since its dealing with time as well. Does anyone know how to do this. Please let me know
Aznxmel is offline   Reply With Quote
Old 03-03-2005, 06:30 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
First things first:
Quote:
how do i add the P and R to the code to recognize it is a sercice code
Code:
char service;
//... later...
if(service == 's' || service == 'S')
{
   //do the standard service calculation.
}
else if(service == 'p' || service == 'P')
{
   //do premium service calculations.
}
__________________
Valmont is offline   Reply With Quote
Old 03-05-2005, 07:54 PM   #3 (permalink)
Aznxmel
Registered User
 
Join Date: Mar 2005
Posts: 3
Aznxmel is on a distinguished road
What am i doing wrong here
Code:
	double accountNumber (0.0);
	double minutesUsed (0.0), totalMinutes (0.0), minutesUsedInDay (0.0);
	double minutesUsedInNight (0.0), amountDueByUser (0.0), balanceDue(0.0);
	double  preiumDay (0.0), preiumNight (0.0);

	char serviceCode (' '), dayOrNight (' ');



//                             Basic Input

    cout << "\n We will now Calculate your Bill" << endl;
	cout << "\n Input Values when prompted" << endl;
	cout << "\n Enter Account Number";
	cin >> accountNumber;
	cout << "\n Enter Service Code 'R' for Regular, 'P' for Premium";
	cin >> serviceCode << endl;
	


//						The Start of using If/Else Statemenets

//						    Calculating Regular Account

if (serviceCode == 'R'|| 'r')
{
	cout<< "\n Welcome to your Regular Account";
	cout<< "\n Enter Minutes Used"; 
	cin >> minutesUsed ;
	
			if (minutesUsed <= 50) = balanceDue + 10;
			else ((minutesUsed - 50) * .20) + 10;
				
	cout<< "\n Balance Due:";
	cin>> balanceDue;
}

else


//						Calculating Premium Account

if (serviceCode == 'P'|| 'p')

	cout<< "\n Welcome to your Premium Account";
	cout<< "\n Chose 'D' for Day Or 'N' for Night";
	cin >> dayOrNight;


//						Calculating Day Time Minutes

if ( dayOrNight == 'D'|| 'd')
{
	cout<< "\n Welcome to your Preium Day Account";
	cout<< "\n Enter Day time Minutes Used";
	cin>> preiumDay;

		if (minutesUsedInDay <= 75) = preiumDay;
		else (minutesUsedInDay - 75) * .10 = preiumDay;

	cout<< "\n Balance Due:"; preiumDay;
}

//						Calculating Night Time Minutes

if ( dayOrNight == 'N'|| 'n')
{
	cout<< "\n Welcome to your Preium Night Account";
	cout<< "\n Enter Night time Minutes Used";
	cin>> preiumNight;
		
		if (preiumNight  <= 100) = preiumNight;
			else (preiumNight - 100) * .05 = preiumNight

	cout<< "\n Balance Due:"; preiumNight;
}

}

Last edited by Valmont; 03-05-2005 at 11:14 PM.
Aznxmel is offline   Reply With Quote
Old 03-05-2005, 11:13 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
First of all, look how I use the if statement, and then compare it with yours:
mine
Code:
if(service == 'p' || service == 'P')
yours
Code:
if(serviceCode == 'P' || 'p')
__________________
Valmont is offline   Reply With Quote
Old 03-06-2005, 06:44 AM   #5 (permalink)
Aznxmel
Registered User
 
Join Date: Mar 2005
Posts: 3
Aznxmel is on a distinguished road
Thanks Valmont, im still having errors because of the curly brackets or too many if else stamtements but your code worked
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <math.h>
 
using namespace std;
 
void main ()
{
 double accountNumber (0.0);
 double minutesUsed (0.0), totalMinutes (0.0), minutesUsedInDay (0.0);
 double minutesUsedInNight (0.0), amountDueByUser (0.0), balanceDue(0.0);
 double  premiumDay (0.0), premiumNight (0.0);
 char service (' '), dayOrNight (' ');
//                             Basic Input
    cout << "\n We will now Calculate your Bill" << endl;
 cout << "\n Input Values when prompted" << endl;
 cout << "\n Enter Account Number";
 cin >> accountNumber;
 cout << "\n Enter Service Code 'R' for Regular, 'P' for Premium"; 
 cin >> service;
//      The Start of using If/Else Statemenets
//          Calculating Regular Account
if(service == 'R' || service == 'r')
{
 cout<< "\n Welcome to your Regular Account";
 cout<< "\n Enter Minutes Used"; 
 cin >> minutesUsed ;
   if (minutesUsed <= 50) 
    balanceDue = minutesUsed + 10;
    cout<< "\n Balance Due: "; balanceDue;
   else 
    balanceDue = ((minutesUsed - 50) * .20) + 10;
    cout<< "\n Balance Due:"; balanceDue;
}
else
//      Calculating Premium Account
if(service == 'p' || service == 'P')
{
 cout<< "\n\n Welcome to your Premium Account";
 cout<< "\n\n Chose 'D' for Day Or 'N' for Night";
 cin >> dayOrNight;
}
//      Calculating Day Time Minutes
 if (dayOrNight == 'D'|| dayOrNight == 'd')
{
 cout<< "\n\n Welcome to your Preium Day Account";
 cout<< "\n\n Enter Day time Minutes Used ";
 cin>> premiumDay; 
  if(minutesUsedInDay <= 75)
   cout<< "\n Premium Day Balance"; premiumDay;
  else 
   premiumDay = ((minutesUsedInDay - 75) * .10);
   cout<< "\n Balance Due:"; premiumDay; 
}
//      Calculating Night Time Minutes
else
 if (dayOrNight == 'N'|| dayOrNight == 'n')
{
 cout<< "\n Welcome to your Premium Night Account";
 cout<< "\n Enter Night time Minutes Used";
 cin>> premiumNight;
  if (premiumNight  <= 100)
    cout<< "\n Premium Night Balance"; premiumNight;
   else 
    premiumNight = (premiumNight - 100) * .05; 
    cout<< "\n Premium Night Balance"; premiumNight;
}
//Return
 return 0;
}

Last edited by redhead; 03-06-2005 at 12:31 PM. Reason: Use [ code] tags
Aznxmel is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need this Microsoft - Matrix video with Bill Gates + Steve Ballmer from Comdex 2003 gicio Lounge 2 11-21-2003 03:59 AM
The wrath of Bill gates sde Lounge 5 02-16-2003 07:46 PM


All times are GMT -8. The time now is 01:14 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting