| | |
Getting errors, not sure how to fix
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 1
Hi there, been having some trouble with a simple program i am trying to write. I'm fairly new to C++, and can't seem to fix the errors im getting. Any ideas or hints would be much appreciated.
These are the errors im getting;
c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(18) : error C2143: syntax error : missing ';' before '&&'
c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(18) : warning C4390: ';' : empty controlled statement found; is this the intent?
c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(23) : error C2181: illegal else without matching if
Again, any hints in the right direction here are much appreciated.
-alias
c++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { double payrate; double hours; double overtimehours; double overtimepay; double totalpay; cout << "How many hours did client work this week?" << endl ; cin >> hours ; cout << "What is their current payrate?" << endl ; cin >> payrate ; if (payrate < 10) && (hours > 40) overtimehours = hours - 40 ; overtimepay = overtimehours * 1.5 * payrate ; totalpay = 40 * payrate + overtimepay ; cout << "The client worked overtime, they are owed: $" << totalpay << endl ; else totalpay = hours * payrate ; cout << "The client is owed: $" << totalpay << endl ; return 0 ; }
These are the errors im getting;
c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(18) : error C2143: syntax error : missing ';' before '&&'
c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(18) : warning C4390: ';' : empty controlled statement found; is this the intent?
c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(23) : error C2181: illegal else without matching if
Again, any hints in the right direction here are much appreciated.
-alias
Last edited by cout<<"alias"; Nov 23rd, 2008 at 7:41 pm.
•
•
Join Date: Jun 2008
Posts: 168
Reputation:
Solved Threads: 3
You messed up your if statement and forgot the braces on the if and else statements, heres the fixed code, good luck.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { double payrate; double hours; double overtimehours; double overtimepay; double totalpay; cout << "How many hours did client work this week?" << endl ; cin >> hours ; cout << "What is their current payrate?" << endl ; cin >> payrate ; if (payrate < 10 && hours > 40) { overtimehours = hours - 40 ; overtimepay = overtimehours * 1.5 * payrate ; totalpay = 40 * payrate + overtimepay ; cout << "The client worked overtime, they are owed: $" << totalpay << endl ; } else { totalpay = hours * payrate ; cout << "The client is owed: $" << totalpay << endl ; } return 0 ; }
Should be..
c++ Syntax (Toggle Plain Text)
if(payrate < 10 && hours > 40) { // begin if //-- your code here } // end if else //...Else
![]() |
Similar Threads
- Help on some errors (Java)
- I can't fix/identify the errors with this program (C++)
- help with few errors (C++)
- Errors...can you help. (Windows NT / 2000 / XP)
- Errors in My XP Error Log. (Windows NT / 2000 / XP)
- Loader.EXE and IEDLL.EXE errors (Web Browsers)
- browsing problems too much! (Web Browsers)
- Im new to this site and c++ (C++)
- Two Problems- "Page Cannot Be Displayed" Errors, Z (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Does BOOST support MVS
- Next Thread: map of arrays?
Views: 447 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project python random read recursion recursive reference return sort stream string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





