473,396 Members | 1,836 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,396 software developers and data experts.

a few simple bugs in this code I wrote

4
I'm writing a pretty basic c++ program and the same error keeps coming up "char n: redefinition."

#include <iostream>
#include <string>
using namespace std;

int main()
{
char n;

cout << "Enter a character: ";
char n = static_cast<int>(n + 1);
cin >> n;


cout << n;

system("pause");

}
May 19 '17 #1

✓ answered by donbock

What do you expect the value of n to be in the computation of n+1 inside the parentheses?

6 1094
donbock
2,426 Expert 2GB
Notice the following two lines in your code:
Expand|Select|Wrap|Line Numbers
  1. char n;
  2. ...
  3. char n = static_cast<int>(n + 1);
Both of these lines declare n as a char. You should only declare it once. Remove "char" from the second line.
May 19 '17 #2
bryan6
4
hm, I changed from
Expand|Select|Wrap|Line Numbers
  1. char n = static_cast<int>(n + 1);
to just
Expand|Select|Wrap|Line Numbers
  1. n = static_cast<int>(n + 1);
but the error is just "uninitialized local variable 'n' used"?
May 19 '17 #3
donbock
2,426 Expert 2GB
What do you expect the value of n to be in the computation of n+1 inside the parentheses?
May 19 '17 #4
bryan6
4
Supposed to be a +1 increase in the character int(s) read.
May 19 '17 #5
bryan6
4
I found it, just had to trim some fat. Your tip helped though.
May 19 '17 #6
donbock
2,426 Expert 2GB
Should the cin line go before the static_cast line?
May 19 '17 #7

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

Similar topics

9
by: johkar | last post by:
I only have IE 6 and dial-up. Can you help me determine which browsers support this code? Thanks, John <html> <head> <title>Fixed Table Headers</title> <script language="JavaScript"...
7
by: Rajani | last post by:
Hello, dim receiptto receiptto="a2z@yahoo.com" set cdoconfig=CreateObject("CDO.configuration") set cdomsg=CreateObject("CDO.Message") with cdoconfig.Fields...
12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
7
by: nalbayo | last post by:
this code i wrote....completly dirty code i think can i make this code more simple and easy? ........&& protected void AddUploadImageButton_Click(object sender, ImageClickEventArgs e) { int...
9
by: javuchi | last post by:
I've been searching thru the library documentation, and this is the best code I can produce for this alogorithm: I'd like to return a dictionary which is a copy of 'another' dictionary whoes...
2
by: Aris | last post by:
Hello! Im trying to implement a queue using a linked list. I've made that code and I expected my Degueue() function to return the value of the key of the node I constructed. But It does not....
1
by: AutoShutdown | last post by:
Can someone post a very simple asp.net code. Simple here means a page displaying records from a table in an sql database. I need to see the connection script. thanks guys. -- AutoShutdown...
53
by: jaso | last post by:
Can you give any comments on this code? I used one goto, is it bad? #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <assert.h> #define NOT_NULL 1
1
by: Girish Kanakagiri | last post by:
How to write simple isapi filter code in C++ Just to Add "Hello World" to the Response ? Can any one please help with initial start up so that I can build up further. It is Urgent... ...
25
by: Chris Thomasson | last post by:
The following code compiles fine with GCC, Comeau, EDG/C++ and VC++ 8/9: #include <cstdio> #include <string> int main() { { std::string names = { "One", "Two", "Three" };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.