473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Expected primary expression before ';',"int" comes because...?

2
Expand|Select|Wrap|Line Numbers
  1. #include<cstdio>
  2. #include<cstdiolib>
  3. #include<iostream>
  4. using namespace std;
  5. int main(int nNumberofArgs, char* pszArgs[])
  6.  
  7. {
  8.     cout<<"Enter your account type";
  9.     int FD;
  10.     if ("FD")
  11.     {
  12.          int p=10000000;
  13.          float r=10;
  14.          int t;
  15.          cin>>t;         
  16.          cout<<p*r*t/100;
  17.  
  18.     }
  19.     int RD;
  20.     else ("RD")    {
  21.          int p=1000000;
  22.          float r=10;
  23.          int t;
  24.          cin>>t;     
  25.          cout<<p*r*t/100;
  26.     }
  27.     system("PAUSE");
  28.     return 0;
  29. }
Dec 17 '12 #1

✓ answered by johny10151981

Interestingly the grammatical error you have made is
Expand|Select|Wrap|Line Numbers
  1.  if(condition)
  2.  {
  3.   statements;
  4.  }
  5.   statements; // this is the line where you have made your grammatical error
  6.  else
  7.  {
  8.   statements;
  9.  }
  10.  
in your original code line 19

Now first you ask account type:
but you didn't write any statement to read the account type

instruction:
Expand|Select|Wrap|Line Numbers
  1. char account_type[4]
  2. cin>>account_type;
  3.  
then you defined integer type FD. FD is a variable without any assigned value.

You don't need FD or RD

What you need is in if condition compare whether the account is FD or RD.
Instruction:
Expand|Select|Wrap|Line Numbers
  1. if(strcomp(account_type,"FD")==0)
  2. {
  3.   Statements;//
  4. }
  5. else if(strcomp(account_type,"RD")==0)
  6. {
  7.  Statements;
  8. }
  9. else 
  10. {
  11.  cout<<"Invalid Account Type Inputted"<<endl;
  12. }
  13.  

7 5747
weaknessforcats
9,208 Expert Mod 8TB
It's probably right here:

Expand|Select|Wrap|Line Numbers
  1.  cout<<int si=p*r*t/100;
You can't create a variable this way. You calling an operator<< function. This one has an ostream& on the left and some argument on the right. You will need to review which types are available as the right hand argument.

If all you want to see is p*r*t/100 then use that and remove the int si=.

BTW: Please use CODE tags on future posts.
Dec 17 '12 #2
yoyo22
2
Thank you. I will use the code tags in my future posts.
Dec 17 '12 #3
divideby0
131 128KB
this doesn't look like either; I'd think it would lead to illegal else without if or such.

what is being tested if("FD")? I've not seen that before.

Expand|Select|Wrap|Line Numbers
  1. if("FD") {
  2.    ...
  3.  
  4. int RD;
  5.  
  6. else("RD") {
  7.    ...
  8. }
if the result of p * r * t / 100 isn't what you'd expect, use parenthesis around the operators.
Dec 17 '12 #4
weaknessforcats
9,208 Expert Mod 8TB
"FD" is a string literal. What is being tested is the address of te literal. This will always be true since the literal exists.

I expect "FD" is a bug since there is an int named FD and probably should have ben coded:

Expand|Select|Wrap|Line Numbers
  1. if (FD)
  2. {
  3. etc...
In this case you are testing the contents of the variable FD to be zero or not. If zero, the if will be false.

On the other hand, nothing is ever put into FD so the whole program makes no sense.
Dec 17 '12 #5
divideby0
131 128KB
Thank you.

I couldn't figure out what if("FD") was supposed to be; is that ever useful? The int was more of what I'd expect... that is, testing a declared type.
Dec 18 '12 #6
weaknessforcats
9,208 Expert Mod 8TB
It may be useful but it's bad practice to have hard-coded values in your code. A better choice is to use a singleton object. The object is created before the program starts and stays around until the program completes. The creation process could read a disc file to get the "FD". That way you could change the value by changing the disc file rather than recompiling the code and sending copies to everyone that has the program.

Expand|Select|Wrap|Line Numbers
  1. Singleton obj;  //reads disc file
  2. int main()
  3. {
  4.    string data;
  5. etc.....
  6.  
  7.    if (data == obj.data())
  8.    {
  9.       //data equal to the disc file value here
  10.    }
  11. etc...
  12. }
As you see, the code is now independent of the value "FD".

A not as good approach is to use a macro. Here you define the macro as "FD". This approach keeps the "FD" in one location but to change it you need to recompile the code:

Expand|Select|Wrap|Line Numbers
  1. #define  VALUE  "FD"
This is put in a header file, say macro.h.

Then you:

Expand|Select|Wrap|Line Numbers
  1. #include <macro.h>
  2.  
  3. int main()
  4. {
  5.    string data;
  6. etc.....
  7.  
  8.    if (data == VALUE)
  9.    {
  10.       //data equal to the macro definition here
  11.    }
  12. etc...
  13.  
Dec 18 '12 #7
johny10151981
1,059 1GB
Interestingly the grammatical error you have made is
Expand|Select|Wrap|Line Numbers
  1.  if(condition)
  2.  {
  3.   statements;
  4.  }
  5.   statements; // this is the line where you have made your grammatical error
  6.  else
  7.  {
  8.   statements;
  9.  }
  10.  
in your original code line 19

Now first you ask account type:
but you didn't write any statement to read the account type

instruction:
Expand|Select|Wrap|Line Numbers
  1. char account_type[4]
  2. cin>>account_type;
  3.  
then you defined integer type FD. FD is a variable without any assigned value.

You don't need FD or RD

What you need is in if condition compare whether the account is FD or RD.
Instruction:
Expand|Select|Wrap|Line Numbers
  1. if(strcomp(account_type,"FD")==0)
  2. {
  3.   Statements;//
  4. }
  5. else if(strcomp(account_type,"RD")==0)
  6. {
  7.  Statements;
  8. }
  9. else 
  10. {
  11.  cout<<"Invalid Account Type Inputted"<<endl;
  12. }
  13.  
Dec 19 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sandy | last post by:
I cannot figure this out. I have the following code: <code> Private: /****************************************************************************** CreateList
4
by: me001 | last post by:
does anyone know hwo i could fix this problem? the error message reads that setName(newFirstname, newLastname); expected primary-expression before ']' token thanks!
3
by: curious2007 | last post by:
Hello, I have the following code: #include <list> #include <iostream> using namespace std; template <class V, class AI, class I, class S> AssocArray<V, AI, I, S>& AssocArray<V, AI, I,...
6
by: Lawrence Spector | last post by:
I ran into a problem using g++. Visual Studio 2005 never complained about this, but with g++ I ran into this error. I can't figure out if I've done something wrong or if this is a compiler bug. ...
4
by: sanctus | last post by:
Is there a typical mistake which generates the error: " error: expected primary-expression before ‘)’ token" because I fail to see why I get this problem and the code is too big to post it here....
8
by: MLZ242 | last post by:
I'm supposed to write a program that is going to calculate absolute value of given number(and print appropriate message) but I'm having tough time with the statements(expected primary-expression...
2
by: emp | last post by:
I have the following class, the primary-expression error takes place in the constructor before "{" token where the maskval array gets initialized. any help would be appreciated emp1953 ...
10
by: tnwagn | last post by:
I have been working on a program and have been unable to resolve these compile issues. g++ main.cpp -o project5.exe main.cpp: In function 'int deal()': main.cpp:20: error: expected...
9
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list...
2
by: Gonzalo Gonza | last post by:
I get this error don't know why Here's the code: double z=dt/dd; double y=(ut-z*ud)/uu; double x=(ct-(z*cd)-(y*cu))/cc; cout<<"x="<<x<<"\n"<<<<"y="<<y<<"\n"<<"z="<<z<<"\n"; The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.