Christos
  • Christos
C++ Please tell me where am I wrong in this program! :( http://pastebin.com/iauPm4q9
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Christos
  • Christos
It's supposed to do this http://screencast.com/t/c5vk81kZY
AravindG
  • AravindG
what error do you get when you run the program ?
Christos
  • Christos
That's the error: "Run-Time Check Failure #3 - The variable 'c' is being used without being initialised."

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

AravindG
  • AravindG
cant you write c = b-40*(a*1.5)+40; instead of const double c = b-40*(a*1.5)+40;
Christos
  • Christos
I tried it in visual studio, it gives errors again
AravindG
  • AravindG
besides it seems the { is misplaced for first if { <-----not here if (kids > 2 && b > 40) <<
Christos
  • Christos
hmm sec
Christos
  • Christos
Now it gives me this "Project : error (null) : Edit and Continue could not create a safe command line to compile changes. UNC, relative and remote drive paths are disallowed. --------------------- Done ----------------------"
AravindG
  • AravindG
ok lemme edit this in my compiler ...I will post it after it gets working
Christos
  • Christos
Thank you so much
RedPrince
  • RedPrince
#include "iostream" using namespace std; int main() { double a, b, kids; cout << "Enter an employee's salary per hour "; cin >> a; cout << "Enter the number of hours he worked in the current week "; cin >> b; cout << "How many kids does he have: "; cin >> kids; if (kids > 2 && b > 40) { const double c = b-40*(a*1.5)+40; cout << "His weekly salaty is: " << (c-(c*6/100)+(c*14/100)-10-35); } if (kids <= 2 && b > 40) { const double c = b-40*(a*1.5)+40; cout << "His weekly salaty is: " << c-(c*6/100)+(c*14/100)-10; } if (kids <= 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)+(d*14/100)-10; } if (kids > 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)+(d*14/100)-10; } system("pause"); return 0; }
AravindG
  • AravindG
well just add the prototype for system function in header and my code below seems to work #include #include int main() { double a, b, d, kids; cout << "Enter an employee's salary per hour "; cin >> a; cout << "Enter the number of hours he worked in the current week "; cin >> b; cout << "How many kids does he have: "; cin >> kids; if (kids > 2 && b > 40) { const double c = b-40*(a*1.5)+40; cout << "His weekly salaty is: " << c-(c*6/100)+(c*14/100)-10-35; } if (kids <= 2 && b > 40) { const double c = b-40*(a*1.5)+40; cout << "His weekly salaty is: " << c-(c*6/100)+(c*14/100)-10; } if (kids <= 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)+(d*14/100)-10; } if (kids > 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)+(d*14/100)-10; } system("pause"); return 0; }
AravindG
  • AravindG
did that help ?
RedPrince
  • RedPrince
Actually., You Are Not Using The Braces Correctly...!! When You Are Not Using Braces, Then Only One Statement After The if Will Be Associated With That if...!! Then, Conditions After That Statement (One Statement) Will Not Be In The Scope Of if Statement..!!
Christos
  • Christos
@AravindG with your script I get this "Project : error (null) : Edit and Continue could not create a safe command line to compile changes. UNC, relative and remote drive paths are disallowed. --------------------- Done ----------------------" @RedPrince with your script I get a run time error
AravindG
  • AravindG
It works for me in turbo c++
Christos
  • Christos
Hmm is this a windows application?? Do you have visual studio ??
AravindG
  • AravindG
Make sure you change the header accordingly for my program , note I changed the header because I am using turbo c++
AravindG
  • AravindG
I also removed using namespace std part
Christos
  • Christos
turbo C++ works without namespace std?
AravindG
  • AravindG
lols It works either way ..was just trying to make the code work for you
Christos
  • Christos
..... :D
Christos
  • Christos
It appears that the code doesn't correspond to this http://screencast.com/t/k3yQmLgQ3UN ? Is there something that must be modified, or am I just silly?
AravindG
  • AravindG
That comes under logical error ...Iets deal with syntax error first
Christos
  • Christos
Yea the syntax error is fixed
AravindG
  • AravindG
wow great !! good work :)
Christos
  • Christos
Could you help me out with the logical error? :S
Christos
  • Christos
It appears that its something small, yet so hard to see
Christos
  • Christos
@AravindG
AravindG
  • AravindG
ok wait ..though its midnight here I dunno if my brain is ready to look at logical errors
AravindG
  • AravindG
Is this urgent ?
Christos
  • Christos
I got a test tomorrow in C++ at my college so I will be studying all night apparently
Christos
  • Christos
Unlucky me :S
AravindG
  • AravindG
Oh I see ..what time is it there now ?
Christos
  • Christos
9:40 pm
AravindG
  • AravindG
here 12:17 am :)
Christos
  • Christos
I see bro, if you are too sleepy then its ok np
AravindG
  • AravindG
nvm .. I can understand the pressure you will be feeling before the test ,I experienced the same 1 month before :) ..I will sort this out
Christos
  • Christos
=) thx bro
AravindG
  • AravindG
yw :)
AravindG
  • AravindG
Ok done ! :) #include #include int main() { double a, b,c, kids; cout << "Enter an employee's salary per hour "; cin >> a; cout << "Enter the number of hours he worked in the current week "; cin >> b; cout << "How many kids does he have: "; cin >> kids; c = a*b; if (kids > 2 && b > 40) { c = c+(1.5*a*(b-40)) ; cout << "His weekly salaty is: " << (c-(c*(6/100))+(c*(14/100))-10-35); } if (kids <= 2 && b > 40) { c = c+(1.5*a*(b-40)) ; cout << "His weekly salaty is: " << c-(c*(6/100))+(c*(14/100))-10; } if (kids <= 2 && b <= 40) { cout << "His weekly salaty is: " << c-(c*(6/100))+(d*(14/100))-10; } if (kids > 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)+(d*14/100)-10; } system("pause"); return 0; }
AravindG
  • AravindG
Hope that works !
Christos
  • Christos
for 100 hours of 2$ per hour and 1 kid it gives me 94$ per week as a result like mine :S
AravindG
  • AravindG
is that right or wrong ?
Christos
  • Christos
its wrong by far :S
Christos
  • Christos
I am using calculator to test the results
AravindG
  • AravindG
ok try other inputs ...meanwhile I will try editing :)
AravindG
  • AravindG
oh got it :)
RedPrince
  • RedPrince
Kindly Tell Me The Error Name....!! I Am Using Code::Blocks..!!
Christos
  • Christos
I solved it guys, here: #include #include using namespace std; int main() { double a, b, d, kids; cout << "Enter an employee's salary per hour "; cin >> a; cout << "Enter the number of hours he worked in the current week "; cin >> b; cout << "How many kids does he have: "; cin >> kids; if (kids > 2 && b > 40) { const double c = (b-40)*(a*1.5)+40*a; cout << "His weekly salaty is: " << c-(c*6/100)-(c*14/100)-10-35; } if (kids <= 2 && b > 40) { const double c = (b-40)*(1.5*a)+40*a; cout << "His weekly salaty is: " << c-(c*6/100)-(c*14/100)-10; } if (kids <= 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)-(d*14/100)-10; } if (kids > 2 && b <= 40) { const double d = a*b; cout << "His weekly salaty is: " << d-(d*6/100)-(d*14/100)-10; } system("pause"); return 0; }
Christos
  • Christos
The tricky line was this c = (b-40)*(1.5*a)+40*a;
Christos
  • Christos
notice the location of "a"
AravindG
  • AravindG
oops yaa !! I made a silly mistake there ! probably because I am almost abt to be asleep
RedPrince
  • RedPrince
I Am Concerned About The Errors, Not The Complete Solution Of The Program...!!
Christos
  • Christos
We fixed the syntax error red price, it was because of the braces
AravindG
  • AravindG
So is your program iver @Christos ? :)
AravindG
  • AravindG
*over
Christos
  • Christos
Yea :D pheu its over
RedPrince
  • RedPrince
Yes, And I Mentioned It Earlier...!! Anyways, Best Of Luck For Your Exam...!! I have Also A Exam Of C++ Today....!!
AravindG
  • AravindG
glad to hear that :) ..Well then I am off ..All the best for your exam :) make sure you put the braces correctly in the program
RedPrince
  • RedPrince
Thanks....!! Of-Course, As For Me These Are The Fundamental Concepts Of C/C++/Java
Christos
  • Christos
Nice red I'm gonna do java as well
RedPrince
  • RedPrince
Many Concepts Are Same In Java...! If You Know About C/C++ Then Java Is Not Much Difficult For You...!! I Am Also Interested In Java...!!
anonymous
  • anonymous
@christos nw dat was funny..
RedPrince
  • RedPrince
How!
anonymous
  • anonymous
@redprince all of u were wresling so much with d code, u were changin d headers, tryin braces and in d end , all der was is a change in equation... i cant stand not laughin wen i guess i to will be in dis position one time.. !! :/

Looking for something else?

Not the answer you are looking for? Search for more explanations.