Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 07-11-2006, 06:03 PM   #1
Daemon Poster
 
Kuberr's Avatar
 
Join Date: Jan 2005
Posts: 609
Send a message via AIM to Kuberr Send a message via MSN to Kuberr
Default C++ Inputs and ASCII

I am currently taking an Intro to C++ course at my local community college.

I have been coding a program, in which I have the following:

cout<<"Please enter in a three-digit number: ";
cin<<Number;

Later on, I have a section that says:

cout<<Number;

Most values work, except values such as 008 don't. The output states that the value of Number is 0. I asked my instructor, and he said that he chose that test data on purpose. He says it has something to do with ASCII. It seems like the C++ is reading the input in with some different method. So how can I fix this?
__________________

__________________
Athlon FX-55 San Diego 2.6GhZ OCed to 3.0GhZ | Mushkin Redline XP 2x1GB PC4000 DDR500 3-3-2-8 OCed to 250MhZ | Seagate Barracuda SATA 400GB 7200RPM HDD | evGA GeForce 6800GT 350/1000 OCed to 425/1150
Kuberr is offline   Reply With Quote
Old 07-12-2006, 03:38 PM   #2
Fully Optimized
 
rakedog's Avatar
 
Join Date: May 2004
Posts: 2,718
Send a message via AIM to rakedog
Default Re: C++ Inputs and ASCII

Can you post your whole program please? And I hope that "cin <<" isn't on purpose.
__________________

__________________
hackthissite.org (criticalsecurity.net) | gentoo.org

The best argument against evolution are creationists themselves. They prove that life is devolving rather than evolving.
rakedog is offline   Reply With Quote
Old 07-12-2006, 03:43 PM   #3
Daemon Poster
 
Kuberr's Avatar
 
Join Date: Jan 2005
Posts: 609
Send a message via AIM to Kuberr Send a message via MSN to Kuberr
Default Re: C++ Inputs and ASCII

Yah. That was kind of by accident. It's a bit too late now, but I'd like to know anyways.

// Dennis Ai
// CSC133-GW
// Lab03.cpp
// This program will determine if the digits of a 3-digit number are odd or even.

#include <iostream.h>
#include <iomanip.h>

int main()
{
//local declarations
int Number, HDCalc, TDCalc, UDCalc, TDQuotient, HDQuotient;
int OddCounter, EvenCounter, ZeroCounter;

OddCounter = 0;
EvenCounter = 0;
ZeroCounter = 0;

cout<<"___________________________________________ ___________________________"<<endl;
cout<<"Dennis Ai CSC133-GW Lab03ex.cpp 7/11/06"<<endl;
cout<<"___________________________________________ ___________________________"<<endl;

cout<<"This program will calculate if the digits of a three-digit number are"<<endl;
cout<<"odd or even."<<endl;
//Imput digits
cout<<"Please enter your three-digit number: ";
cin>>Number;
//Determine unit digit's odd/even attribute
UDCalc = Number % 2;
if (UDCalc==1)
OddCounter++;
else if (UDCalc==0)
{
UDCalc = Number % 10;
if (UDCalc==0)
ZeroCounter++;
else EvenCounter++;
}
//Determine ten digit's odd/even attribute
TDCalc = Number / 10;
TDQuotient = TDCalc % 2;
if (TDQuotient==1)
OddCounter++;
else if (TDQuotient==0)
{
TDCalc = TDCalc % 10;
if (TDCalc==0)
ZeroCounter++;
else EvenCounter++;
}
//Determine hundred digit's odd/even attribute
HDCalc = Number / 100;
HDQuotient = HDCalc % 2;
if (HDQuotient==1)
OddCounter++;
else if (HDQuotient==0)
{
HDCalc = HDCalc % 10;
if (HDCalc==0)
ZeroCounter++;
else EvenCounter++;
}
//Rewrite three-digit number
cout<<"The three-digit number you entered was: "<<Number<<endl;
//Print out even/odd attribute
if (OddCounter==3)
cout<<"The number contains all odd digits.";
else if (EvenCounter==3)
cout<<"The number contains all even digits.";
else if (ZeroCounter==3)
cout<<"The number contains all zeroes.";
else if ((OddCounter==1) && (EvenCounter==1) && (ZeroCounter==1))
cout<<"The number contains odd, even, and zero digits.";
else if ((OddCounter>=1) && (ZeroCounter>=1))
cout<<"The number contains odd and zero digits.";
else if ((EvenCounter>=1) && (ZeroCounter>=1))
cout<<"The number contains even and zero digits.";
else if ((OddCounter>=1) && (EvenCounter>=1))
cout<<"The number contains both odd and even digits.";
cout<<OddCounter<<EvenCounter<<ZeroCounter;
//End main
return 0;
}
__________________
Athlon FX-55 San Diego 2.6GhZ OCed to 3.0GhZ | Mushkin Redline XP 2x1GB PC4000 DDR500 3-3-2-8 OCed to 250MhZ | Seagate Barracuda SATA 400GB 7200RPM HDD | evGA GeForce 6800GT 350/1000 OCed to 425/1150
Kuberr is offline   Reply With Quote
Old 07-13-2006, 03:38 AM   #4
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++ Inputs and ASCII

i cannot reproduce your problem...

the whole enter 3 digits 00x and get it to equal zero... i always get the value of the number i enter.

maybe you can explain to us how to get the error?
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 07-13-2006, 08:02 AM   #5
Daemon Poster
 
Kuberr's Avatar
 
Join Date: Jan 2005
Posts: 609
Send a message via AIM to Kuberr Send a message via MSN to Kuberr
Default Re: C++ Inputs and ASCII

It's just 008 and 009?
__________________
Athlon FX-55 San Diego 2.6GhZ OCed to 3.0GhZ | Mushkin Redline XP 2x1GB PC4000 DDR500 3-3-2-8 OCed to 250MhZ | Seagate Barracuda SATA 400GB 7200RPM HDD | evGA GeForce 6800GT 350/1000 OCed to 425/1150
Kuberr is offline   Reply With Quote
Old 07-13-2006, 01:55 PM   #6
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++ Inputs and ASCII

well i've tried 008 and 009 and other numbers with two zeros preceding it, still can't get the error.

i tried with the code you've supplied and just a simple cin >> var; cout << var; program, always comes out the correct value.
__________________

__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:37 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0