5 Replies - 1338 Views - Last Post: 28 February 2009 - 01:52 PM Rate Topic: -----

#1 ic3e   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 13-October 08

divide and conquer

Post icon  Posted 28 February 2009 - 12:53 PM

I know there is a simple solution, so here is my program.

 #include<iostream>
 #include<string>

using namespace std;

int main()
{
double min;
double BasicRate;
double CStates;
double FStates;
double cost = 0;

string inp = "";
string temp = "";
BasicRate = 0.02;
CStates = 1.25 * BasicRate;
FStates = 1.75 * BasicRate;
int callCount;



for(int i = 0; i < 10; i++)
{
 temp = inp[0];
 if(temp == "q" || temp == "Q") break;
 cout << "------------------------------------------\n";
 cout << "Q & A Telephone service.\n";
 cout << "------------------------------------------\n";
 cout << " plaease enter your destenation number ex."
"111-111-1111\n";
 cin >> inp;
 temp = inp[0] + inp[1] + inp[2];

 
 {
 if(temp == "405") cost = BasicRate * min * (rand() % 180);
 if( temp == "550" ||  temp == "520") cost= CStates * min * (rand() %
180);
 if(temp == "620" || temp  == "650") cost = FStates * min * (rand() %
180);
 cout << cost"\n";

 }

cout << " over limit\n ";
}



Its not complete, Im just dividing and conquering portions at a time. when I run this program, it prompts the user to enter A phone number, after the user enters the phone number, it loops right back around to the beginning, which is ok for now. Im just trying to figure out how to make the program go throught the loop only 10 ten times then to tell the user his time is up. should I use a for loop or a while loop?

Is This A Good Question/Topic? 0
  • +

Replies To: divide and conquer

#2 programble   User is offline

  • (cons :dic :head)

Reputation: 50
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: divide and conquer

Posted 28 February 2009 - 12:56 PM

Your code looks just fine, are you getting errors?
Was This Post Helpful? 0
  • +
  • -

#3 ic3e   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 13-October 08

Re: divide and conquer

Posted 28 February 2009 - 01:14 PM

View Postprogramble, on 28 Feb, 2009 - 11:56 AM, said:

Your code looks just fine, are you getting errors?


Yeah, it works so far, when I run this program, it prompts the user to enter A phone number, after the user enters the phone number, it loops right back around to the beginning, which is ok for now. Im just trying to figure out how to make the program go throught the loop only 10 ten times then to tell the user his time is up. should I use a for loop or a while loop?
Was This Post Helpful? 0
  • +
  • -

#4 krisku   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 65
  • Joined: 13-December 08

Re: divide and conquer

Posted 28 February 2009 - 01:27 PM

Can use do-while loop. Syntax:

do {
something
something2
} while(expression)



For counting, can use variable with initial value 0. ;-)

This post has been edited by krisku: 28 February 2009 - 01:29 PM

Was This Post Helpful? 0
  • +
  • -

#5 ic3e   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 13-October 08

Re: divide and conquer

Posted 28 February 2009 - 01:42 PM

View Postkrisku, on 28 Feb, 2009 - 12:27 PM, said:

Can use do-while loop. Syntax:

do {
something
something2
} while(expression)



For counting, can use variable with initial value 0. ;-)


I incorporated this method

#include<iostream>
 #include<string>

using namespace std;

int main()
{
double min;
double BasicRate;
double CStates;
double FStates;
double cost = 0;

string inp = "";
string temp = "";
BasicRate = 0.02;
CStates = 1.25 * BasicRate;
FStates = 1.75 * BasicRate;
int callCount;

do
{

for(int i = 0; i < 10; i++)
{
 temp = inp[0];
 if(temp == "q" || temp == "Q") break;
 cout << "------------------------------------------\n";
 cout << "Q & A Telephone service.\n";
 cout << "------------------------------------------\n";
 cout << " plaease enter your destenation number ex."
"111-111-1111\n";
 cin >> inp;
 temp = inp[0] + inp[1] + inp[2];

 
 {
 if(temp == "405") cost = BasicRate * min * (rand() % 180);
 if( temp == "550" ||  temp == "520") cost= CStates * min * (rand() %
180);
 if(temp == "620" || temp  == "650") cost = FStates * min * (rand() %
180);
 cout << cost"\n";

 }
 } while( cin < 10);
cout << " over limit\n ";
}



I ran it, and got multiple errors, any Ideas?
Was This Post Helpful? 0
  • +
  • -

#6 programble   User is offline

  • (cons :dic :head)

Reputation: 50
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: divide and conquer

Posted 28 February 2009 - 01:52 PM

Use a for loop.
for (int c = 0; c < 10; c++)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1