473,395 Members | 1,885 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.

Can't get this to work in Visual Studio 2005

ShawnRR
Hi,

I am learning C using VS2005 and I can't get this code to work. It is out of the book but it does not compile and run. What am i doing wrong?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.  
  4. int main (void)
  5. {
  6.     int    integerVar = 100;
  7.     float  floatingVar = 331.79;
  8.     double doubleVar = 8.44e+11;
  9.     char   charVar = 'W';
  10.  
  11.     _Bool boolVar = 0;
  12.  
  13.  
  14.     printf ("integerVar = %i\n", integerVar);
  15.     printf ("floatingVar = %f\n", floatingVar);
  16.     printf ("doubleVar = %e\n", doubleVar);
  17.     printf ("doubleVar = %g\n", doubleVar);
  18.     printf ("charVar = %c\n", charVar);
  19.  
  20.     printf ("boolVar = %i\n", boolVar);
  21.  
  22.     return 0;
  23. }
  24.  
These are the errors I am getting:

Expand|Select|Wrap|Line Numbers
  1. Warning    1    warning C4305: 'initializing' : truncation from 'double' to 'float'    c:\test\workspace\workspace\program 4-1.c    7
  2. Error    2    error C2065: '_Bool' : undeclared identifier    c:\test\workspace\workspace\program 4-1.c    11
  3. Error    3    error C2146: syntax error : missing ';' before identifier 'boolVar'    c:\test\workspace\workspace\program 4-1.c    11
  4. Error    4    error C2065: 'boolVar' : undeclared identifier    c:\test\workspace\workspace\program 4-1.c    11
  5.  
Thanks,
Shawn
Aug 24 '07 #1
2 1738
ilikepython
844 Expert 512MB
Hi,

I am learning C using VS2005 and I can't get this code to work. It is out of the book but it does not compile and run. What am i doing wrong?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.  
  4. int main (void)
  5. {
  6.     int    integerVar = 100;
  7.     float  floatingVar = 331.79;
  8.     double doubleVar = 8.44e+11;
  9.     char   charVar = 'W';
  10.  
  11.     _Bool boolVar = 0;
  12.  
  13.  
  14.     printf ("integerVar = %i\n", integerVar);
  15.     printf ("floatingVar = %f\n", floatingVar);
  16.     printf ("doubleVar = %e\n", doubleVar);
  17.     printf ("doubleVar = %g\n", doubleVar);
  18.     printf ("charVar = %c\n", charVar);
  19.  
  20.     printf ("boolVar = %i\n", boolVar);
  21.  
  22.     return 0;
  23. }
  24.  
These are the errors I am getting:

Expand|Select|Wrap|Line Numbers
  1. Warning    1    warning C4305: 'initializing' : truncation from 'double' to 'float'    c:\test\workspace\workspace\program 4-1.c    7
  2. Error    2    error C2065: '_Bool' : undeclared identifier    c:\test\workspace\workspace\program 4-1.c    11
  3. Error    3    error C2146: syntax error : missing ';' before identifier 'boolVar'    c:\test\workspace\workspace\program 4-1.c    11
  4. Error    4    error C2065: 'boolVar' : undeclared identifier    c:\test\workspace\workspace\program 4-1.c    11
  5.  
Thanks,
Shawn
C doesn't have a boolean type. Maybe, add this:
Expand|Select|Wrap|Line Numbers
  1. typedef short int _Bool
  2.  
Aug 25 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
This warning:
Warning 1 warning C4305: 'initializing' : truncation from 'double' to 'float' c:\test\workspace\workspace\program 4-1.c 7
comes from:
float floatingVar = 331.79;
Symbolic constants like 331.79 are double. float is smaller than double so some data may be lost. This should be coded as 331.79f od 331.79F to tell the compiler to create the constant as a float.
Aug 25 '07 #3

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

Similar topics

4
by: Jack | last post by:
Will these be add-ons to Whidby?
0
by: Scott Nonnenberg [MSFT] | last post by:
"The Visual Studio Debugger Do you have some burning questions or comments about SQL, C#, VB, C++, or script debugging support in Visual Studio? Want to know more about Visual Studio 2005's...
3
by: Thom Little | last post by:
I have ASP.NET websites deployed on a number of servers. Thee were developed with Visual Studio 2003. Is it true that Visual Studio 2005 only supports .NET Framework 2.0 and I will be required...
1
by: jmespinosabaviera | last post by:
1) Does visual studio standard 2005 include visual basic ?. 2) What difference is there between the visual studio standard 2005 and the professional version ? 3) What difference is there...
5
by: blackdog | last post by:
I have installed Visual Studio 2005, on the CD show Visual Studio 2005 team suite with 3 disks. I used to use Visual studio .NET 2003 and I used command csc.exe to compile csharp program. but...
4
by: John Bailo | last post by:
Can I use the .NET 3.0 framework with Visual Studio 2003?
9
by: Jason | last post by:
Hi all, I am no longer able to publish a web site project using Visual Studio 2005 Professional. I am publishing it to an FTP url, and this used to work just fine. I enter the username and...
0
by: Steven Prasil | last post by:
When I start my VisualStudio 2005 it creates automatically new folders: D:\work\Visual Studio 2005 D:\work\Visual Studio 2005\Projects D:\work\Visual Studio 2005\Templates Yes, in VS menu ...
0
by: marathoner | last post by:
I am currently migrating my Visual C++ 6.0 applications to Visual Studio 2005. I am getting compiler errors involving the VS2005's platform SDK. When I removed directory references to that SDK,...
6
by: raylopez99 | last post by:
Will ASP.NET 3.0 work under Visual Studio 2005? And what is a good newbie ASP.NET book? Subject: Will ASP.NET 3.0 work under Visual Studio 2005? And what is a good newbie ASP.NET book? My...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.