PLEASE help with loop, this has logic errors

This is a discussion on PLEASE help with loop, this has logic errors within the C++ Programming forums, part of the General Programming Boards category; Please help me, its not a whole lot but its giving me a hard time. So, Here is the code ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    1

    Exclamation PLEASE help with loop, this has logic errors

    Please help me, its not a whole lot but its giving me a hard time. So, Here is the code that I am having problems with, I have some major logic errors in it, but I would assume that would be it.

    Code:

    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;

    //Programmer : cerealstone
    //Assignment : programming
    //Purpose : To take a call start time and end time. Calculate the rate
    // tax, and total for the call. Plus, to keep track of number of calls,
    // and to keep track of total time.

    int main()
    {
    int start_time, stop_time, start_mins, stop_mins, Elaps, call, length;
    int Elaps1, Elaps2;
    double tax, rate, cost, prime, base, total;
    char answer;

    call=0;
    length=0;


    do
    {
    //get start time
    cout<< "Start time : ";
    cin>>start_time;
    if(start_time>=2100);
    prime=(length/10)*.09+length%10;

    //get stop time
    cout<< "Stop time : ";
    cin>>stop_time;
    cout<<endl;

    //compute start minutes
    start_mins = (start_time / 100) * 60 + start_time % 100;

    //compute stop minutes
    stop_mins = (stop_time / 100) * 60 + stop_time % 100;

    //conversion for time that is uneven
    if (stop_mins < start_mins)
    stop_mins=stop_mins + 1440;

    //compute time elapsed
    length=stop_mins- start_mins;

    //Continue
    cout<<"Do you wish to enter another call (y or n)? ";
    cin>>answer;
    cout<<endl;

    //adding a call per call
    call=call+1;
    }
    while (answer=='y');

    if(answer=='n');
    {
    //output results
    cout<<"You had "<<call<<" calls which took a total of "<<length<<" minutes calling time."<<endl;
    cout<<"You will be charged: "<<endl;

    //prime time calling after 9:00, 9 cents a min, tax .04
    if(prime)
    {
    cout<< "Call cost: " << prime <<endl;
    tax=prime*.04;
    cout<<"Tax : "<<tax<<endl;
    total=prime+tax;
    cout<<"Total : "<<total<<endl;
    }

    //base charge is 14 cents a min, tax .04
    else
    {
    rate=(length/10)*.14+length%10;
    cout<<"Call cost: "<<rate<<endl;
    tax=rate*.04;
    cout<<"Tax : "<<tax<<endl;
    total=rate+tax;
    cout<<"Total : "<<total<<endl;
    }
    }

    return 0;
    Last edited by cerealstone; 02-21-2003 at 12:22 AM.

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399

    Re: PLEASE help with loop, this has logic errors

    Code:
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    
    <snip>
    
    if(start_time>=2100); // take out the ;
    
     <snip>
    
     if(answer=='n');  //take out the ;
    
    <snip>
    
     return 0;
    // add an ending }
    I don't know if the code will actually do what you want it to, but at least the if-statements will work. Also, use code tags.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutiliplcation Program that uses a (do, while, and for loop)?
    By Debbie Bremer in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2008, 06:04 PM
  2. Can a "switch" be inside a loop?
    By gmk0351 in forum C Programming
    Replies: 5
    Last Post: 03-28-2008, 05:47 PM
  3. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  4. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 02:48 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21