RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 813 | Replies: 2 | Thread Tools  Display Modes
Join Date: Oct 2007
Posts: 2
Reputation: ComputerLand is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ComputerLand ComputerLand is offline Offline
Newbie Poster

Need advice and base conversion. Please help as soon as you can. Thanks

  #1  
Oct 19th, 2007
#include <iostream.h>
int main(void){

int base;
char num;

cout<< "Enter a base: ";
cin >> base;
while((base>=2)&&(base<=10)){
}
cin>>num;
while((num-'0') < (base)) && (c>='0'){
base>=base*2+(num-'0')
cin.get>>num;
}
cout<<base;
cin.putback>>num;
return 0;
}

Clearly, this program doesn't work very well. I am in need of help. The teacher really gave us nothing that was to be in the program. Just what the coding means like what is a character, what is a loop, etc. I got that far, but now I need some help. The program is supposed to do this:

1. Convert any base into a decimal
2. Skip over anything not in the base

An example of the input and output would be like this:

Enter a base: 5
Enter a number: 3435//=5559*1
Converted value: 269

The number supposed to convert was 3431 because everything else was a non-numeric character OR a digit not in the base. As we all know, there is no "5" in base 5. Decimal 5 is represented by "10" in base 5, so we need to skip over that.

Can someone give me an explanation of what eof, putback, and get are? My teacher told us to read about it while doing the program. I tried to apply it, but probably didn't do so properly. Can someone get me a good explanation when I apply it to cin. Thanks. Any help solving my program or giving me what restrictions to put or what to alter or anything of the sort woudl be a wondrous beacon of light for me. Thanks again. Also, can someone recommend a C++ book to me or a site with a good tutorial? I have been at this for only 10 days.
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:37 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC