Welcome to Dream.In.Code
Become a C++ Expert!

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




If Else Statement Errors

 
Reply to this topicStart new topic

If Else Statement Errors, Please help i am going blind!

Tara200
28 Oct, 2007 - 02:37 PM
Post #1

New D.I.C Head
*

Joined: 13 Oct, 2007
Posts: 39


My Contributions
: In function ‘int main()’:
:38: error: expected primary-expression before ‘else’
:38: error: expected `;' before ‘else’
:47: error: expected primary-expression before ‘else’
:47: error: expected `;' before ‘else’
CODE
include <iostream>

using namespace std;


double Dep1= 250000;// Declare Variables
double Dep2= 25000;
double Dep3= 10000;
double Inter1= 3.20;
double Inter2= 3.16;
double Inter3= 2.76;
double cash = 0;

int main()

{
  cout << "Deposit: "; // Enter Pounds as a Single Integer
  cin  >> cash;       //Read the Amount of Pounds

   {  if  ( cash > 50000);

    double cashIn  = cash / 100 * 3.20;
    double IntPaid = cashIn;
    cout << "Rate = "     << 3.20 << endl;
    cout << "Interest = " << IntPaid << endl;
  }
  {  
     else if (cash < 50000);
       double cashIn = cash / 100 * 3.16;
       double IntPaid = cashIn;
       cout << "Rate ="     << 3.16 << endl;
       cout << "Interest = "<< IntPaid << endl;
  }
  {  
     else if (cash <= 10000);
    
     double cashIn = cash / 100 * 2.76;
     double IntPaid = cashIn;
     cout << "Rate ="     << 2.76 << endl;
     cout << "Interest =" << IntPaid << endl;
   }

}


Hi could you tell me what is wrong with this code at all please as i keep getting the error message posted above-it is a programe that is meant to 'ask for a deposit sum and print out the interest rate and the total interest gained from the deposit. Three different interest rates are used and each one will calculate the rate dependent on the amount of cash deposit ie: Dep1 calculates the rate for sums between 50.000-250.000 etc. Any feedback will be greatly appreciated as this is an assignment thats due in this week. Thankyou very much. Tara200

This post has been edited by Tara200: 29 Oct, 2007 - 01:13 PM
User is offlineProfile CardPM
+Quote Post

spullen
RE: If Else Statement Errors
28 Oct, 2007 - 03:04 PM
Post #2

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
if else statement should look like this:
CODE

if(something >= something2){
      //do something
}else if (somethinf > 0){
      //do something else
}



This post has been edited by spullen: 28 Oct, 2007 - 03:05 PM
User is offlineProfile CardPM
+Quote Post

Tara200
RE: If Else Statement Errors
29 Oct, 2007 - 01:11 PM
Post #3

New D.I.C Head
*

Joined: 13 Oct, 2007
Posts: 39


My Contributions
QUOTE(spullen @ 28 Oct, 2007 - 04:04 PM) *

if else statement should look like this:
CODE

if(something >= something2){
      //do something
}else if (somethinf > 0){
      //do something else
}



Hi thanks for your help i tried this code but it didn't work i still got the same errors?I am a beginner so not sure how to code an If Else statement successfully.This is an assignement that has to be in Thursday so i am grateful of any help at all.
Any ideas would be greatfully appreciated blink.gif
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: If Else Statement Errors
29 Oct, 2007 - 01:21 PM
Post #4

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



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

My Contributions
well check the new tutorial by jjhaag

http://www.dreamincode.net/forums/showtopic36256.htm
User is offlineProfile CardPM
+Quote Post

barnwillyb
RE: If Else Statement Errors
29 Oct, 2007 - 01:27 PM
Post #5

D.I.C Head
**

Joined: 22 May, 2007
Posts: 55


My Contributions
QUOTE(Tara200 @ 28 Oct, 2007 - 03:37 PM) *

: In function ‘int main()’:
:38: error: expected primary-expression before ‘else’
:38: error: expected `;' before ‘else’
:47: error: expected primary-expression before ‘else’
:47: error: expected `;' before ‘else’
CODE
include <iostream>

using namespace std;


double Dep1= 250000;// Declare Variables
double Dep2= 25000;
double Dep3= 10000;
double Inter1= 3.20;
double Inter2= 3.16;
double Inter3= 2.76;
double cash = 0;

int main()

{
  cout << "Deposit: "; // Enter Pounds as a Single Integer
  cin  >> cash;       //Read the Amount of Pounds

   {  if  ( cash > 50000);

    double cashIn  = cash / 100 * 3.20;
    double IntPaid = cashIn;
    cout << "Rate = "     << 3.20 << endl;
    cout << "Interest = " << IntPaid << endl;
  }
  {  
     else if (cash < 50000);
       double cashIn = cash / 100 * 3.16;
       double IntPaid = cashIn;
       cout << "Rate ="     << 3.16 << endl;
       cout << "Interest = "<< IntPaid << endl;
  }
  {  
     else if (cash <= 10000);
    
     double cashIn = cash / 100 * 2.76;
     double IntPaid = cashIn;
     cout << "Rate ="     << 2.76 << endl;
     cout << "Interest =" << IntPaid << endl;
   }

}


Hi could you tell me what is wrong with this code at all please as i keep getting the error message posted above-it is a programe that is meant to 'ask for a deposit sum and print out the interest rate and the total interest gained from the deposit. Three different interest rates are used and each one will calculate the rate dependent on the amount of cash deposit ie: Dep1 calculates the rate for sums between 50.000-250.000 etc. Any feedback will be greatly appreciated as this is an assignment thats due in this week. Thankyou very much. Tara200



QUOTE
This should work:


CODE
int main (int argc, char * const argv[]) {
    double cash = 0.0;
    // Enter Pounds as a Single Integer
    cout << "Deposit: ";
        cin  >> cash;       //Read the Amount of Pounds

    if (cash > 50000) {
        double cashIn  = cash / 100 * 3.20;
        double IntPaid = cashIn;
        cout << "Rate = "     << 3.20 << endl;
        cout << "Interest = " << IntPaid << endl;
    }
    
     else if (cash < 50000) {
        double cashIn = cash / 100 * 3.16;
        double IntPaid = cashIn;
        cout << "Rate ="     << 3.16 << endl;
        cout << "Interest = "<< IntPaid << endl;
    }
    
     else if (cash <= 10000) {
        double cashIn = cash / 100 * 2.76;
        double IntPaid = cashIn;
        cout << "Rate ="     << 2.76 << endl;
        cout << "Interest =" << IntPaid << endl;
    }

    return 0;
}

User is offlineProfile CardPM
+Quote Post

Tara200
RE: If Else Statement Errors
29 Oct, 2007 - 02:04 PM
Post #6

New D.I.C Head
*

Joined: 13 Oct, 2007
Posts: 39


My Contributions
QUOTE(barnwillyb @ 29 Oct, 2007 - 02:27 PM) *

QUOTE(Tara200 @ 28 Oct, 2007 - 03:37 PM) *

: In function ‘int main()’:
:38: error: expected primary-expression before ‘else’
:38: error: expected `;' before ‘else’
:47: error: expected primary-expression before ‘else’
:47: error: expected `;' before ‘else’
CODE
include <iostream>

using namespace std;


double Dep1= 250000;// Declare Variables
double Dep2= 25000;
double Dep3= 10000;
double Inter1= 3.20;
double Inter2= 3.16;
double Inter3= 2.76;
double cash = 0;

int main()

{
  cout << "Deposit: "; // Enter Pounds as a Single Integer
  cin  >> cash;       //Read the Amount of Pounds

   {  if  ( cash > 50000);

    double cashIn  = cash / 100 * 3.20;
    double IntPaid = cashIn;
    cout << "Rate = "     << 3.20 << endl;
    cout << "Interest = " << IntPaid << endl;
  }
  {  
     else if (cash < 50000);
       double cashIn = cash / 100 * 3.16;
       double IntPaid = cashIn;
       cout << "Rate ="     << 3.16 << endl;
       cout << "Interest = "<< IntPaid << endl;
  }
  {  
     else if (cash <= 10000);
    
     double cashIn = cash / 100 * 2.76;
     double IntPaid = cashIn;
     cout << "Rate ="     << 2.76 << endl;
     cout << "Interest =" << IntPaid << endl;
   }

}


Hi could you tell me what is wrong with this code at all please as i keep getting the error message posted above-it is a programe that is meant to 'ask for a deposit sum and print out the interest rate and the total interest gained from the deposit. Three different interest rates are used and each one will calculate the rate dependent on the amount of cash deposit ie: Dep1 calculates the rate for sums between 50.000-250.000 etc. Any feedback will be greatly appreciated as this is an assignment thats due in this week. Thankyou very much. Tara200



QUOTE
This should work:


CODE
int main (int argc, char * const argv[]) {
    double cash = 0.0;
    // Enter Pounds as a Single Integer
    cout << "Deposit: ";
        cin  >> cash;       //Read the Amount of Pounds

    if (cash > 50000) {
        double cashIn  = cash / 100 * 3.20;
        double IntPaid = cashIn;
        cout << "Rate = "     << 3.20 << endl;
        cout << "Interest = " << IntPaid << endl;
    }
    
     else if (cash < 50000) {
        double cashIn = cash / 100 * 3.16;
        double IntPaid = cashIn;
        cout << "Rate ="     << 3.16 << endl;
        cout << "Interest = "<< IntPaid << endl;
    }
    
     else if (cash <= 10000) {
        double cashIn = cash / 100 * 2.76;
        double IntPaid = cashIn;
        cout << "Rate ="     << 2.76 << endl;
        cout << "Interest =" << IntPaid << endl;
    }

    return 0;
}


THANKYOU SO MUCH!!-it does work fine!! You have got me out of a big C++ hole! biggrin.gif
User is offlineProfile CardPM
+Quote Post

tikotiko
RE: If Else Statement Errors
29 Oct, 2007 - 07:26 PM
Post #7

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 32


My Contributions
you have to take off the commas after the if and before the else statement and it should work
User is offlineProfile CardPM
+Quote Post

Smarf
RE: If Else Statement Errors
31 Oct, 2007 - 07:52 AM
Post #8

D.I.C Head
**

Joined: 21 Sep, 2007
Posts: 80



Thanked: 2 times
My Contributions
Two things based on this:

CODE
{  if  ( cash > 50000);

    double cashIn  = cash / 100 * 3.20;
    double IntPaid = cashIn;
    cout << "Rate = "     << 3.20 << endl;
    cout << "Interest = " << IntPaid << endl;
  }


Remove the semicolon after your if condition
It should just be:

CODE
if (powerLevel > 9000)


Also, don't put the brace BEFORE the if portion, it surrounds
all the statements that are processed when your statement
is true like this:

CODE
if (powerLevel > 9000)
{
   cout << "It's over 9000!";
   cout << "Arggh!";
}


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 12:42PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

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