ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello everyone,
this is what my program is supposed to do: initially prompts the user for the area code. Then the program continuously accepts phone call data, and displays data for any phone call to or from the specified area code. The program ends when -1 is input for the area code.
Code:
#include <iostream>
using namespace std;
const float LOW_RATE=0.10;
const float HIGH_RATE=0.13;
const float TIME_LIMIT=20;
int
main()
{
int givenAreaCode;
int custAreaCode;
int custPhoneNum;
int calledAreaCode;
int calledPhoneNum;
float minutes;
float price;
cout << "Please enter area code: ";
cin >> givenAreaCode;
cout << "Please enter your area code: ";
cin >> custAreaCode;
cout << "Please enter your Phone Number: ";
cin >> custPhoneNum;
cout << "Please enter called area code: ";
cin >> calledAreaCode;
cout << "Please enter called number: ";
cin >> calledPhoneNum;
cout << "Minutes: ";
cin >> minutes;
do {
if (custAreaCode = -1){
}else{
if (custAreaCode == givenAreaCode || calledAreaCode == givenAreaCode)
if (custAreaCode!= calledAreaCode && minutes > TIME_LIMIT)
price = minutes * LOW_RATE;
else
price = minutes * HIGH_RATE;
cout << " your area code is " << custAreaCode << endl;
cout << " your phone number is " << custPhoneNum << endl;
cout << " your called area code is " << calledAreaCode << endl;
cout << " your called number is " << calledPhoneNum << endl;
cout << " your price is " << price << endl;
}
}
while (custAreaCode = -1);
cout << "Please enter area code: ";
cin >> givenAreaCode;
cout << "Please enter your area code: ";
cin >> custAreaCode;
cout << "Please enter your Phone Number: ";
cin >> custPhoneNum;
cout << "Please enter called area code: ";
cin >> calledAreaCode;
cout << "Please enter called number: ";
cin >> calledPhoneNum;
cout << "Minutes: ";
cin >> minutes;
cin.get();
cin.ignore();
return 0;
}
the do while has problems. it COMPILES but doesnt work.
any thoughts?
The compiler compiles as it has to do because there are not syntax problems and it does its job, but you wronged the symbols, you seem confused about the sign " = " and the sign " == " and wronging these symbols you won't get any error if not logic ones and wrong results Correct the symbols, it might work.
I did not look at the whole program before, just found those (obvious) comparison/assignment bugs. Even now, I'm not going to fix the whole thing, since a) I don't know how it is supposed to work and b) I'm not really into doing other peoples' homework.
Anyway, the structure is really wrong. I can't even elaborate, the use of that do { } while is.. *cough*. And at the end you prompt for more data and just discard it.*
All in all, I guess you should really read up on how loops and conditional checks work.
*- reminds me of "What does your robot do?" "It collects data about the surrounding environment, then discards it and drives into walls".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.