Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-17-2007, 06:32 AM   #1
Member (4 bit)
 
Join Date: Aug 2007
Posts: 9
Beginner C++ help

#include
#include
using namespace std;

int main ()
{
int i, f, m;
string n;
double a = 2.60;
double b = 3.36;
double c = 2.79;
double t;

cout << "Initial meter reading:";
cin >> i;
cin.ignore(100000, '\n');

cout << "Final meter reading:";
cin >> f;
cin.ignore(100000, '\n');

int hcf = f - i;

cout << "Customer name:";
cin >> n;
cin.ignore(100000, '\n');

cout << "Month number (1=Jan, 2=Feb, etc.):";
cin >> m;
cin.ignore(100000, '\n');

if (m == 6 || 7 || 8 || 9 || 10)
{
if (hcf <= 46)
{
t = hcf * a;
}
else if (hcf > 46)
{
t = ((hcf - 46)*b) + 119.60;
}
}

else
{
if (hcf <= 32)
{
t = hcf * a;
}
else if (hcf > 32)
{
t = ((hcf - 32)*c) + 83.20;
}
}

cout << "---\nThe bill for " << n << " is $" << t << "\n";
}

The problem is in regards to the bolded part. I have the condition only if m is a number 6-10, but any number I input, it still uses the bold code block instead of going to the italicized else block. What am I doing wrong? And, how do I make it that in the underlined output, the number is always shown as a nonnegative number with at least one digit to the left and exactly two digits to the right of the decimal point?

Also, I'm not understanding too well why I don't get an error for using double, but I do for float. I thought float could be used for decimals too.

Please point out any mistakes in the code or anything that is not needed yet included in there. Thanks in advance.
finalcloud13 is offline   Reply With Quote
Old 10-17-2007, 07:32 AM   #2
Moderator
Staff
Premium Member
 
Join Date: Aug 2003
Location: Richmond, VA
Posts: 7,835
Try rephrasing the top bolded conditional as such:
PHP Code:
if (>=&& <=10)
{
... 
Where, of course, the "..." will be the rest of your code.

kram
__________________
"For today, goodbye. For tomorrow, good luck. And forever, Go Blue!"
University of Michigan President Mary Sue Coleman
kram 2.0 is offline   Reply With Quote
Old 10-17-2007, 08:42 AM   #3
Wx geek
 
blue60007's Avatar
 
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
Is it even valid to do m == 6 || 7 ... would think you would have to do m == 6 || m == 7. Seems counter-intuitive, but I'm not sure that's a valid boolean expression.

Can you provide a couple examples of what is being outputted for t, and what you are expecting? You are getting something like x.xx ? Might make more sense to me to see what you're expecting.
__________________
"It is the way of man to make monsters and it is the nature of monsters to destroy their makers."

Last edited by blue60007; 10-17-2007 at 08:45 AM.
blue60007 is offline   Reply With Quote
Old 10-17-2007, 03:36 PM   #4
Member (4 bit)
 
Join Date: Aug 2007
Posts: 9
Thank you very much, the

if (m >=6 && m <=10)
{

fixed the problem
finalcloud13 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Networking beginner - help needed mickey Networking & Online Security 4 04-26-2006 05:01 PM
Beginner user alert. kev7555 Networking & Online Security 0 07-16-2004 11:49 PM
Beginner Linux Book mikezel Linux OS and Software Assistance 9 03-06-2004 03:03 PM
Is it really worth it for a beginner? Apothary Computer Hardware 17 09-10-2003 02:58 AM
linux beginner frenchfried Linux OS and Software Assistance 6 04-05-2003 08:25 AM


All times are GMT -5. The time now is 07:32 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2