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

Join 135,935 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,674 people online right now. Registration is fast and FREE... Join Now!




If Statement Syntax Error '>' during debug

 
Reply to this topicStart new topic

If Statement Syntax Error '>' during debug

lockdown
1 Oct, 2007 - 03:13 PM
Post #1

D.I.C Regular
Group Icon

Joined: 29 Sep, 2007
Posts: 376



Thanked: 1 times
Expert In: PC, Support

My Contributions
I am creating a simple program that takes the cost of 5 items a user inputs and finds the subtotal and total with 5% sales tax. I have created the program to adjust the setprecision() value based on what the subtotal cost and total cost come out to (basically so it will always have the .00 ex $100.00 and 10.00)


The problem I am having is I keep getting the debug error error C2059: syntax error : '>'. I have gone threw the code and found that the problem is relating to my if statement in some same but I cant determine how since it all looks correct.

Hear is the code
CODE

// This application will take 5 items that a user enters and calculate the total price with 5% sales tax
// Introduction to programming C++

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

    // Delcares 1-5, Subtotal, SalesTax, and Total which are set to 0.
    // Everything except for tax is set to 0 so large default values are not assigned before the users enters in the value being asked
    // Once the user enters in the value for the particular item it will be stored as that new value

    double item1=0, // Declares items 1-5
           item2=0,
           item3=0,
           item4=0,
           item5=0,
           stotal=0,// Delcares subtotal
           stax=0,  // Delcares Sales Tax
           total=0; // Declares Total
    const double tax=.05; //Declared amount of tax (5% = .05) as a constant since it will never change in the application
    int x=4; // Value for setprecision
            
    // Display message to user explaining what the application dose
    cout << "This applicaiton will calculate the total cost of 5 items with 5% sales tax\n" << endl;
    
    // Ask user for cost of item 1
    cout << "\nPlease enter the cost of item 1: $";
    
    // Users input for item 1
    cin >> item1;

    // Ask user for cost of item 2
    cout << "\nPlease enter the cost of item 2: $";

    // Users input for item 2
    cin >> item2;

    // Ask user for cost of item 3
    cout << "\nPlease enter the cost of item 3: $";

    // Users input for item 3
    cin >> item3;

    // Ask user for cost of item 4
    cout << "\nPlease enter the cost of item 4: $";

    // Users input for item 4
    cin >> item4;

    // Ask user for cost of item 5
    cout << "\nPlease enter the cost of item 5: $";

    // Users input for item 5
    cin >> item5;

    // Sub total = the sum of items 1-5
    stotal = item1 + item2 + item3 + item4 + item5;

    // Sales tax = subtoal * tax (5%)
    stax = stotal*tax;
    
    // Total = sales tax + subtotal
    total = stax + stotal;

    if (stotal => 100 && total => 100)
        x=5;

    cout << showpoint << "\nSubtotal: $" << setprecision(x) << stotal;
    cout << showpoint << "\nSales Tax: 5.0%";
    cout << "\n****************";
    cout << showpoint << "\nTotal: $" << setprecision(x)<< total;
    cout << "\n****************" << endl;

    // Will pause application
    system("Pause");

    return 0;
}


I have set the int x=4 so if stotal and total => 100 it will get place 4 in setprecision(x).

This post has been edited by lockdown: 1 Oct, 2007 - 03:13 PM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: If Statement Syntax Error '>' During Debug
1 Oct, 2007 - 03:24 PM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,009



Thanked: 5 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi the problem is here:


if (stotal => 100 && total => 100)

there is no => operator, in C++, not that I know of.

So instead use the greater or equal to operator >=.

User is offlineProfile CardPM
+Quote Post

lockdown
RE: If Statement Syntax Error '>' During Debug
1 Oct, 2007 - 03:31 PM
Post #3

D.I.C Regular
Group Icon

Joined: 29 Sep, 2007
Posts: 376



Thanked: 1 times
Expert In: PC, Support

My Contributions
I had a feeling it was going to be something like that I messed up. I got confused on which side the =. Thanks that fixed my problem.
User is offlineProfile CardPM
+Quote Post

Smarf
RE: If Statement Syntax Error '>' During Debug
2 Oct, 2007 - 06:55 AM
Post #4

D.I.C Head
**

Joined: 21 Sep, 2007
Posts: 80



Thanked: 2 times
My Contributions
QUOTE(PennyBoki @ 1 Oct, 2007 - 04:24 PM) *

Hi the problem is here:


if (stotal => 100 && total => 100)

there is no => operator, in C++, not that I know of.

So instead use the greater or equal to operator >=.


It's always last but it helps if you say it outloud:

Not equal too: !=
Less than or equal too: <=
Greater than or equal too: >=

and the hardest to remember
Equal too: ==
User is offlineProfile CardPM
+Quote Post

Smarf
RE: If Statement Syntax Error '>' During Debug
2 Oct, 2007 - 07:04 AM
Post #5

D.I.C Head
**

Joined: 21 Sep, 2007
Posts: 80



Thanked: 2 times
My Contributions
PS: You might want to get in the habit of using brackets when doing if statements because it can lead to logic errors if you wanted more than one statement to execute.

Your example:

CODE
if (stotal >= 100 && total >= 100)
         {
             x=5;
          }

    cout << showpoint << "\nSubtotal: $" << setprecision(x) << stotal;
    cout << showpoint << "\nSales Tax: 5.0%";
    cout << "\n****************";
    cout << showpoint << "\nTotal: $" << setprecision(x)<< total;
    cout << "\n****************" << endl;


Put { } around the x=5. It works out because it's just a single statement that there is no logic error;.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:34AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month