-
May 7th, 2015, 02:14 PM
#1
#define not working with my input
Code isn't fully complete but I don't want to continue when my #define isn't even working, what am I doing wrong here? Please help, and go easy on me, this is my first code ever. Thanks!
#define PI 3.14159
#include <iostream>
using namespace std;
int main()
{
int answer;
cout << "The area of a circle is" <<PI>> "* radius * radius"<<endl; //This line is a calculation and cannot be done until you read in the radius from the user, i.e. you cannot do a calculation until
//Ask the user for the radius of the pie in inches.
cout << "What is the radius of the pie in inches?" << endl;
//read in the radius
//Ask the user for the length of the shelf.
cout << "What is the length of the shelf?" <<endl;
//readin the length
//Ask the user for the width of the shelf.
cout << "What is the width of the shelf?" <<endl;
//read in the width
//Calculate the area of the pie.
//Calculate the area of the shelf.
//ex: sum = num1 + num2; example of a sum calculation
//Calculate the total number of pies that can fit on the shelf.
cout << "What is the total number of pies that can fit on the shelf?" <<endl; //This is not an output statement this is also a calculation, your answer which should be the area of your shelves
//divided by the area of your pies
system("pause");
//Display a message telling the user how many pies can fit on the shelf
cout << "The number of pies that can fit on the shelf is" << answer << endl;
return 0;
}
-
May 7th, 2015, 02:25 PM
#2
Re: #define not working with my input
Your #define is working fine. You have a little issue here though
cout << "The area of a circle is" <<PI>> "* radius * radius"<<endl;
-
May 7th, 2015, 02:30 PM
#3
Re: #define not working with my input
Thanks for the reponse. Maybe it's my compiler, I'm using DevC++ 5.11. When I type in #define PI 3.14159 it all stays once color when I thought "PI" was suppose to be a different color, I don't know. Still says it's incorrect, like it's not acknowledging my #define.
-
May 7th, 2015, 02:32 PM
#4
Re: #define not working with my input
Once I changed the >> to << it compiled cleanly for me using VS 2012.
-
May 7th, 2015, 02:36 PM
#5
Re: #define not working with my input
Guess I'll be trying a new compiler, thanks a lot GCDEF
-
May 7th, 2015, 02:39 PM
#6
Re: #define not working with my input
When posting code, please use code tags. Go Advanced, select the formatted code and click '#'.
Still says it's incorrect, like it's not acknowledging my #define.
Have you changed your code as per GCDEF's post? What is incorrect? What error message is the compiler displaying?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 7th, 2015, 02:39 PM
#7
Re: #define not working with my input
Possibly that compiler has something else already defined as PI. Try calling it something else. The exact error message would help.
-
May 7th, 2015, 02:41 PM
#8
Re: #define not working with my input
Originally Posted by deadfolx
Guess I'll be trying a new compiler, thanks a lot GCDEF
If you are using Windows, have a look at MS VS 2013 community edition. This is free. See https://www.visualstudio.com/downloa...sual-studio-vs
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 7th, 2015, 02:45 PM
#9
Re: #define not working with my input
Excellent thank you. My apologies for not using a tag, I'll do so in the future for sure. As far as the code is concerned, it was saying that there was no given value for "PI" and highlighted the entire line in red.
-
May 7th, 2015, 03:46 PM
#10
Re: #define not working with my input
Fixed it guys, thanks again
Last edited by deadfolx; May 7th, 2015 at 03:56 PM.
-
May 7th, 2015, 05:27 PM
#11
Re: #define not working with my input
Originally Posted by deadfolx
Fixed it guys, thanks again
What was it?
-
June 5th, 2015, 11:50 PM
#12
Re: #define not working with my input
Originally Posted by GCDEF
What was it?
it was a stupid mistake...I put the #define in the wrong spot and some other careless mistakes that I looked over. And devc++ was a P.O.S compiler, VS is much better, thanks again GCDEF
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|