Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,668 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,151 people online right now. Registration is fast and FREE... Join Now!




If/Else Statements

 
Reply to this topicStart new topic

If/Else Statements, And whatever else I am doing wrong. -.-

Tanooki
post 5 Sep, 2007 - 07:38 AM
Post #1


New D.I.C Head

*
Joined: 5 Sep, 2007
Posts: 1


My Contributions


I found a lot of my mistakes from the guidance of a friend and looking more carefully, but I am still getting an error message for something I see nothing wrong with. The last else statement has two errors I don't know how to fix, and "int main()".

CODE

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

main()
{
      float a, b, c, d;
      cout << "What was last month's reading?" << endl;
      cin >> a;
      cout << "What is this month's reading?" << endl;
      cin >> b;
      c = 1000 - a + b;
      
if (c <= 70) {d == 5;
}
else if (70 <= c && c <= 170)
{
     d == ((c - 70) * .05) + 5;
}
else if (170 <= c && c <= 400)
{
     d == ((c - 170) * .025) + 10;
}
else (c => 400) {d == ((c - 400) * .015) + 15.75;
}

      cout << "Last Month's Reading: "<<a<<" cubic metres.\n";
      cout << "This Month's Reading: "<<b<<" cubic metres.\n";
      cout << "Gas Used: "<<c<<" cubic metres.\n";
      cout << "Total Charges: "<<d<< "dollars.\n";
      system ("pause");
}



Original Post:
I'm pretty much lost on what to do. It tells me it is expecting primary-expression. I saw another thread on it, but when I tried the suggested solution, it didn't work. It also tells me some numbers cannot be used as a function... But I don't know what that means.

CODE
#include<iostream>
#include<cstdlib>
using namespace std;
main()
{
      float a, b, c, d;
      cout << "What was last month's reading?" << endl;
      cin >> a;
      cout << "What is this month's reading?" << endl;
      cin >> b;
      c = 1000 - a + b;
      
if (c <= 70) {d == 5();
}
else if (70 <= c <= 170) {d = ((c - 70) * .05) + 5();
}
else if (170 <= c <= 400) {d = ((c - 170) * .025) + 10();
}
else (c => 400) {d = ((c - 400) * .015) + 15.75();
}

      cout << "Last Month's Reading: "<<a<<" cubic metres.\n";
      cout << "This Month's Reading: "<<b<<" cubic metres.\n";
      cout << "Gas Used: "<<c<<" cubic metres.\n";
      cout << "Total Charges: "<<d<< "dollars.\n";
      system ("pause");
}


This post has been edited by Tanooki: 5 Sep, 2007 - 07:56 AM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 5 Sep, 2007 - 08:01 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


CODE

main()

should be
CODE

int main()

You have parenthses after several numbers...what is your intent for them. This would normally denote a function call.
User is online!Profile CardPM

Go to the top of the page

no2pencil
post 5 Sep, 2007 - 08:08 AM
Post #3


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(Tanooki @ 5 Sep, 2007 - 08:38 AM) *

CODE

if (c <= 70) {d == 5;
}
else if (70 <= c && c <= 170)
{
     d == ((c - 70) * .05) + 5;
}
else if (170 <= c && c <= 400)
{
     d == ((c - 170) * .025) + 10;
}
else (c => 400) {d == ((c - 400) * .015) + 15.75;
}


To keep from getting errors, I suggest cleaning up your code a bit.

CODE

if (c <= 70) {
    d == 5;
}
else {
    if (70 <= c && c <= 170) {
     d == ((c - 70) * .05) + 5;
    }
    else {
        if (170 <= c && c <= 400) {
        d == ((c - 170) * .025) + 10;
        }
        else (c => 400) { // You have a condition on this line with no if...
            d == ((c - 400) * .015) + 15.75;
        }


ect... I think you get the point. If you keep your code clean, it will be much easier to troubleshoot.
User is offlineProfile CardPM

Go to the top of the page

Tomas
post 5 Sep, 2007 - 01:21 PM
Post #4


New D.I.C Head

Group Icon
Joined: 12 Jun, 2007
Posts: 34



Dream Kudos: 100
My Contributions


i just had a quick glace (literally) so i may be wrong by saying the in the last else statement you have written
CODE
else (c => 400)

where it should be
CODE
else(c >= 400)

i am not quite sure wheter it matters which way it is around but that is the way i would do it, and it has never failed for me smile.gif
User is offlineProfile CardPM

Go to the top of the page

Apples
post 5 Sep, 2007 - 02:28 PM
Post #5


New D.I.C Head

*
Joined: 15 Nov, 2006
Posts: 21


My Contributions


QUOTE(Tomas @ 5 Sep, 2007 - 02:21 PM) *

i just had a quick glace (literally) so i may be wrong by saying the in the last else statement you have written
CODE
else (c => 400)

where it should be
CODE
else(c >= 400)

i am not quite sure wheter it matters which way it is around but that is the way i would do it, and it has never failed for me smile.gif


i don't think that matters. if i remember correctly, i've done it both ways before. biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 5 Sep, 2007 - 02:36 PM
Post #6


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,062



Thanked 175 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


I suggest you make it a habit to use the second example (>=) because there is other meanings for => in several languages and its just a bad habit you don't want to get into. Besides, it is the standard and makes your code proper and readable. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 05:56AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month