Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
#include <iostream.h> #include <stdlib.h> #include <math.h> int main ( ) { double noe, nod, dc1, dc2, dc3, dc4, t; cout << "Ent...Asked by sonnytsn
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
int main ( )
{
double noe, nod, dc1, dc2, dc3, dc4, t;
cout << "Enter number of eggs: ";
cin >> noe;
nod = noe / 12;
dc1 = .50 / 12;
dc2 = .45 / 12;
dc3 = .40 / 12;
dc4 = .35 / 12;
cout.setf(ios::fixed);
cout.precision(3);
if (nod >4) {
goto 1;
}
if ( (nod >4) && (nod <6) ) {
goto 2;
}
else
}
{
if ( (nod >6) && (nod <11) )
}
goto 3;
{
else
}
{
if (nod >11)
}
goto 4;
{
else
}
{
1:
t = noe * dc1;
cout << "Your cost is $0.50 per dozen or " << dc1 << " per egg.";
cout << endl;
goto end;
2:
t = noe * dc2;
cout << "Your cost is $0.45 per dozen or " << dc2 << " per egg.";
goto end;
3:
t = noe * dc3;
cout << "Your cost is $0.40 per dozen or " << dc3 << " per egg.";
goto end;
4:
t = noe * dc4;
cout << "Your cost is $0.35 per dozen or " << dc4 << " per egg.";
cout.setf(ios::fixed);
cout.precision(2);
cout << "Your bill comes to " << t;
cout << endl;
cout << endl;
system("Pause");
return (0);
}
#include <stdlib.h>
#include <math.h>
int main ( )
{
double noe, nod, dc1, dc2, dc3, dc4, t;
cout << "Enter number of eggs: ";
cin >> noe;
nod = noe / 12;
dc1 = .50 / 12;
dc2 = .45 / 12;
dc3 = .40 / 12;
dc4 = .35 / 12;
cout.setf(ios::fixed);
cout.precision(3);
if (nod >4) {
goto 1;
}
if ( (nod >4) && (nod <6) ) {
goto 2;
}
else
}
{
if ( (nod >6) && (nod <11) )
}
goto 3;
{
else
}
{
if (nod >11)
}
goto 4;
{
else
}
{
1:
t = noe * dc1;
cout << "Your cost is $0.50 per dozen or " << dc1 << " per egg.";
cout << endl;
goto end;
2:
t = noe * dc2;
cout << "Your cost is $0.45 per dozen or " << dc2 << " per egg.";
goto end;
3:
t = noe * dc3;
cout << "Your cost is $0.40 per dozen or " << dc3 << " per egg.";
goto end;
4:
t = noe * dc4;
cout << "Your cost is $0.35 per dozen or " << dc4 << " per egg.";
cout.setf(ios::fixed);
cout.precision(2);
cout << "Your bill comes to " << t;
cout << endl;
cout << endl;
system("Pause");
return (0);
}
Answers
Answered by
Quidditch
A few things to check:
The first test is true for any number greater than 4. If you enter 5, the first test will go to label 1. Maybe the first test should be less than 4.
Another item to check:
You are not including the endpoints in the range check.
From your code:
if ( (nod >4) && (nod <6) ) {
goto 2;
}
else
}
{
if ( (nod >6) && (nod <11) )
}
goto 3;
---------------
If you enter 6, it will not satisfy either of these.
The first test is true for any number greater than 4. If you enter 5, the first test will go to label 1. Maybe the first test should be less than 4.
Another item to check:
You are not including the endpoints in the range check.
From your code:
if ( (nod >4) && (nod <6) ) {
goto 2;
}
else
}
{
if ( (nod >6) && (nod <11) )
}
goto 3;
---------------
If you enter 6, it will not satisfy either of these.
Answered by
sonnytsn
i did that. it still doesn't work :*(
thanks for your help but can you try compliaing it?
thanks for your help but can you try compliaing it?
Answered by
Quidditch
Does it compile OK?
If so, what is the test input that is failing?
If so, what is the test input that is failing?
Answered by
Quidditch
Looking again:
Labels cannot begin with a number.
1: is wrong
L1: would be OK
Try changing your labels ( and goto's).
Labels cannot begin with a number.
1: is wrong
L1: would be OK
Try changing your labels ( and goto's).
Answered by
Quidditch
Your braces are backwards after your "else"
should be:
else {
}
Your 3rd and 4th "if" statements have backward braces also.
should be:
else {
}
Your 3rd and 4th "if" statements have backward braces also.
Answered by
sonnytsn
it says it has a unidentifair berfore numberic constant
Answered by
Quidditch
OK,
Post the code you just tried.
Also, which line is the compiler complaining about?
Post the code you just tried.
Also, which line is the compiler complaining about?
Answered by
sonnytsn
still doesn't work :(
Answered by
Andrea
how do you convert 2 for binary to decimal using c++ program
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.