Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How would you turn 7 into 07?
New Posts  All Forums:Forum Nav:

How would you turn 7 into 07?

post #1 of 8
Thread Starter 
The program asks for an input and the number will be just one digit, For example, 6 or 7, and of course it gets assigned to a variable. Thus, how would you change that value that is assigned 7 from 7 to 07?
Deus Ex Machina
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel core i5 2500k @ 3.8ghz Asus p8z68-v GTX Geforce EVGA SC 660Ti 16GB G.Skill 2133 Ripjaws X series 
Hard DriveOSPowerCase
Crucial m4 64GB + WD Caviar Green 1.5TB + samsu... Windows 7 Ultimate 64bit Antec 550 watt modular psu Cooler Master HAF 912 
  hide details  
Reply
Deus Ex Machina
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel core i5 2500k @ 3.8ghz Asus p8z68-v GTX Geforce EVGA SC 660Ti 16GB G.Skill 2133 Ripjaws X series 
Hard DriveOSPowerCase
Crucial m4 64GB + WD Caviar Green 1.5TB + samsu... Windows 7 Ultimate 64bit Antec 550 watt modular psu Cooler Master HAF 912 
  hide details  
Reply
post #2 of 8
Quote:
Originally Posted by sam114455 View Post

The program asks for an input and the number will be just one digit, For example, 6 or 7, and of course it gets assigned to a variable. Thus, how would you change that value that is assigned 7 from 7 to 07?

what language?
Case Labs th10
(21 items)
 
Haf 912
(7 items)
 
3570k
(8 items)
 
CPUMotherboardGraphicsRAM
i7 3930k Rampage 4 Extreme EVGA GTX 690 signature Dominator GT 16gb 
Hard DriveHard DriveOptical DriveCooling
Samsung 830 256gb Samsung 830 256gb Asus 24x RX 480 
CoolingCoolingCoolingCooling
RX 480 9x Gentle Typhoon AP-15 XSPC 5.25 Dual Bay Reservoir MCP 355 
MonitorKeyboardPowerCase
CrossOver 27Q K90 Corsair AX1200 CaseLabs th10 
MouseMouse PadOtherOther
M60 GTX 690 Signature Edition Mousepad :P 3x 20" Cold Cathodes Bitfenix Alchemy Cable Extensions-Red 
Other
Lamptron FC8 
CPUMotherboardGraphicsRAM
i5 2500k @4.8 GHz 1.4v Asus P8z68-v/gen 3 EVGA GTX 580 @875 MHz 8 gb Corsair Vengeance 1600 
Hard DriveHard DriveCooling
Samsung 830 64gb SSD WD 500gb HDD H60 
CPUMotherboardGraphicsRAM
i5 3570k @4.4 GHz asrock z77 pro3 HD 4000 8gb samsung 30nm 
Hard DriveOptical DriveCoolingOS
ocz agility 3- 120gb asus 24x dvd antec kuhler h20 620 win. 7  
  hide details  
Reply
Case Labs th10
(21 items)
 
Haf 912
(7 items)
 
3570k
(8 items)
 
CPUMotherboardGraphicsRAM
i7 3930k Rampage 4 Extreme EVGA GTX 690 signature Dominator GT 16gb 
Hard DriveHard DriveOptical DriveCooling
Samsung 830 256gb Samsung 830 256gb Asus 24x RX 480 
CoolingCoolingCoolingCooling
RX 480 9x Gentle Typhoon AP-15 XSPC 5.25 Dual Bay Reservoir MCP 355 
MonitorKeyboardPowerCase
CrossOver 27Q K90 Corsair AX1200 CaseLabs th10 
MouseMouse PadOtherOther
M60 GTX 690 Signature Edition Mousepad :P 3x 20" Cold Cathodes Bitfenix Alchemy Cable Extensions-Red 
Other
Lamptron FC8 
CPUMotherboardGraphicsRAM
i5 2500k @4.8 GHz 1.4v Asus P8z68-v/gen 3 EVGA GTX 580 @875 MHz 8 gb Corsair Vengeance 1600 
Hard DriveHard DriveCooling
Samsung 830 64gb SSD WD 500gb HDD H60 
CPUMotherboardGraphicsRAM
i5 3570k @4.4 GHz asrock z77 pro3 HD 4000 8gb samsung 30nm 
Hard DriveOptical DriveCoolingOS
ocz agility 3- 120gb asus 24x dvd antec kuhler h20 620 win. 7  
  hide details  
Reply
post #3 of 8
Thread Starter 
oh sorry, C++.
Deus Ex Machina
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel core i5 2500k @ 3.8ghz Asus p8z68-v GTX Geforce EVGA SC 660Ti 16GB G.Skill 2133 Ripjaws X series 
Hard DriveOSPowerCase
Crucial m4 64GB + WD Caviar Green 1.5TB + samsu... Windows 7 Ultimate 64bit Antec 550 watt modular psu Cooler Master HAF 912 
  hide details  
Reply
Deus Ex Machina
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel core i5 2500k @ 3.8ghz Asus p8z68-v GTX Geforce EVGA SC 660Ti 16GB G.Skill 2133 Ripjaws X series 
Hard DriveOSPowerCase
Crucial m4 64GB + WD Caviar Green 1.5TB + samsu... Windows 7 Ultimate 64bit Antec 550 watt modular psu Cooler Master HAF 912 
  hide details  
Reply
post #4 of 8
i would just pad the output with a zero, because 07 = 7
Code:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>                                        

int main(void)
{
        int x(0);
        std::cin >> x;
        std::printf("%02d \n",x);                     //you pad the output of x with a zero

        system("pause");                              //type this if the console closes immediately
        return 0;
}

http://www.cplusplus.com/reference/clibrary/cstdio/printf/

edit::note that if your number is more than one digit, you'll need to change: %02 to: %0(# of digits+1)
Edited by Forrester - 10/5/12 at 6:31pm
Case Labs th10
(21 items)
 
Haf 912
(7 items)
 
3570k
(8 items)
 
CPUMotherboardGraphicsRAM
i7 3930k Rampage 4 Extreme EVGA GTX 690 signature Dominator GT 16gb 
Hard DriveHard DriveOptical DriveCooling
Samsung 830 256gb Samsung 830 256gb Asus 24x RX 480 
CoolingCoolingCoolingCooling
RX 480 9x Gentle Typhoon AP-15 XSPC 5.25 Dual Bay Reservoir MCP 355 
MonitorKeyboardPowerCase
CrossOver 27Q K90 Corsair AX1200 CaseLabs th10 
MouseMouse PadOtherOther
M60 GTX 690 Signature Edition Mousepad :P 3x 20" Cold Cathodes Bitfenix Alchemy Cable Extensions-Red 
Other
Lamptron FC8 
CPUMotherboardGraphicsRAM
i5 2500k @4.8 GHz 1.4v Asus P8z68-v/gen 3 EVGA GTX 580 @875 MHz 8 gb Corsair Vengeance 1600 
Hard DriveHard DriveCooling
Samsung 830 64gb SSD WD 500gb HDD H60 
CPUMotherboardGraphicsRAM
i5 3570k @4.4 GHz asrock z77 pro3 HD 4000 8gb samsung 30nm 
Hard DriveOptical DriveCoolingOS
ocz agility 3- 120gb asus 24x dvd antec kuhler h20 620 win. 7  
  hide details  
Reply
Case Labs th10
(21 items)
 
Haf 912
(7 items)
 
3570k
(8 items)
 
CPUMotherboardGraphicsRAM
i7 3930k Rampage 4 Extreme EVGA GTX 690 signature Dominator GT 16gb 
Hard DriveHard DriveOptical DriveCooling
Samsung 830 256gb Samsung 830 256gb Asus 24x RX 480 
CoolingCoolingCoolingCooling
RX 480 9x Gentle Typhoon AP-15 XSPC 5.25 Dual Bay Reservoir MCP 355 
MonitorKeyboardPowerCase
CrossOver 27Q K90 Corsair AX1200 CaseLabs th10 
MouseMouse PadOtherOther
M60 GTX 690 Signature Edition Mousepad :P 3x 20" Cold Cathodes Bitfenix Alchemy Cable Extensions-Red 
Other
Lamptron FC8 
CPUMotherboardGraphicsRAM
i5 2500k @4.8 GHz 1.4v Asus P8z68-v/gen 3 EVGA GTX 580 @875 MHz 8 gb Corsair Vengeance 1600 
Hard DriveHard DriveCooling
Samsung 830 64gb SSD WD 500gb HDD H60 
CPUMotherboardGraphicsRAM
i5 3570k @4.4 GHz asrock z77 pro3 HD 4000 8gb samsung 30nm 
Hard DriveOptical DriveCoolingOS
ocz agility 3- 120gb asus 24x dvd antec kuhler h20 620 win. 7  
  hide details  
Reply
post #5 of 8
^ Looks like all he needs. Just two things:

1. Use CODE tags
2. Replace system("PAUSE") with getchar() as the former is platform specific.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #6 of 8
Thread Starter 
thanks guys but never mind. I'm retarded i could just put an if statement in between the cout section.
Deus Ex Machina
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel core i5 2500k @ 3.8ghz Asus p8z68-v GTX Geforce EVGA SC 660Ti 16GB G.Skill 2133 Ripjaws X series 
Hard DriveOSPowerCase
Crucial m4 64GB + WD Caviar Green 1.5TB + samsu... Windows 7 Ultimate 64bit Antec 550 watt modular psu Cooler Master HAF 912 
  hide details  
Reply
Deus Ex Machina
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel core i5 2500k @ 3.8ghz Asus p8z68-v GTX Geforce EVGA SC 660Ti 16GB G.Skill 2133 Ripjaws X series 
Hard DriveOSPowerCase
Crucial m4 64GB + WD Caviar Green 1.5TB + samsu... Windows 7 Ultimate 64bit Antec 550 watt modular psu Cooler Master HAF 912 
  hide details  
Reply
post #7 of 8
Quote:
Originally Posted by sam114455 View Post

thanks guys but never mind. I'm retarded i could just put an if statement in between the cout section.

To do what? Check if it's only one character? I can't see how an if block would be any nicer than string formatting unless there is something else that you also need the code to do that you haven't told us.
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
post #8 of 8
printf is a very handy tool to use and works in a number of different languages too (C++ / Java / Perl / etc). You'd be doing yourself a massive favour in the long run if you learn to use it. smile.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How would you turn 7 into 07?