Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 9th, 2006, 5:47 PM   #1
Barb
Newbie
 
Join Date: Apr 2006
Posts: 6
Rep Power: 0 Barb is on a distinguished road
Help with Loop and Calculation

Hi - I'm haveing problems with the calculation and loop. Here are my problems:
Calculation - When I enter in a start time and a length time the calculation is not coming out correctly and I can't seem to figure out why.
Loop - I had to write a line to say that you may enter another set by hitting the n key. I cannot figure out how to make it so that it automatically goes to the next set without hitting the n key.
Any help is greatly appreciated. Here is what I have coded so far.

#include <stdio.h>
#include <conio.h>

#define rate .10
#define discounta .50
#define discountb .15
#define tax .04

void getStartTime(int time);
void getLengthofCall(int length);
void calcGross(int time, int length, double gross);
void calcNet(int time, int length,double gross, double net);
void displayReport(double gross, double net, char input);
void end();

int main()
{
    int time;
    int length;
    double gross;
    double net;
	char input;
    
    getStartTime(time);
    getLengthofCall(length);
    calcGross(time, length, gross);
    calcNet(time, length, gross, net);
    displayReport(gross, net, input);
	return 0;
}

void getStartTime(int time)
{
     printf("Please input start time: ");
     scanf("%d", &time);
	 if(time >= 2401 || time <= -1)
	 {
		 printf("Invalid time. Please input a time between 0 and 2400.\n\n");
		 main();
	 }
}

void getLengthofCall(int length)
{
     printf("Please input call length: ");
     scanf("%d", &length);
}

void calcGross(int time, int length, double gross)
{
    if(time <= 800 || time >= 1800 && time <= 60)
    {
        gross = length*rate*discounta;
    }
    else if(time <= 800 || time >= 1800 && time >= 60)
    {
        gross = length*rate*discounta*discountb;
    }
    else
    {
        gross = length*rate;      
    }
}

void calcNet(int time, int length, double gross, double net)
{
    if(time <= 800 || time >= 1800 && time <= 60)
    {
        net = gross*tax+gross;
    }
    else if(time <= 800 || time >= 1800 && time >= 60)
    {
        net = gross*tax+gross;
    }
    else
    {
        net = gross*tax+gross;       
    }
}
void displayReport(double gross, double net, char input)
{
     printf("\nGross: %lf\nNet: %lf", gross, net);
	 printf("\nYou may enter another set by hitting the n key.\n");
	 printf("\nYou may exit this program by hitting the e key.\n");
	 scanf("%s", &input);
	 if (input!='e')
	 {
	 	main();
	 }
	 else if(input='e')
	 {
		 end();
	 }
}
void end()
{
     printf("\n\nThank you for using this phone calculator program!\n");
}

This is my output
Please input start time: 1600
Please input call length: 15

Gross: -92559631349317831000000000000000000000000000000000 000000000000.000000
Net: -92559631349317831000000000000000000000000000000000 000000000000.000000
You may enter another set by hitting the n key.

You may exit this program by hitting the e key.
Barb is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC