New Posts  All Forums:Forum Nav:

C++ restart program help! :)

post #1 of 34
Thread Starter 
Hey guys. I made a currency converter program and I was wondering what function I use to make it restart? I have it so that it asks if you want to quit or not, and if the person answers with either 'y' or 'yes', it will quit, but now I need the function so that it will restart if they enter 'n' or 'no'!

Thanks for the help, guys!
Elliott
2011
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom X4 955 BE @ 3.2Ghz Gigabyte 880GA-UD3H XFX 6870 Dual Fan  4Gb G.Skill Ripjaw 1333Mhz 
Hard DriveOptical DriveCoolingOS
80Gb Seagate SATA LG DVD+ Zalman CNPS 9700 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Black 23" Full HD - LED Backlit Microsoft Media Pro Antec Earthwatts 600w Antec 900 (modded) 
MouseMouse Pad
Logitech MX518 Steelpad 5L 
  hide details  
Reply
2011
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom X4 955 BE @ 3.2Ghz Gigabyte 880GA-UD3H XFX 6870 Dual Fan  4Gb G.Skill Ripjaw 1333Mhz 
Hard DriveOptical DriveCoolingOS
80Gb Seagate SATA LG DVD+ Zalman CNPS 9700 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Black 23" Full HD - LED Backlit Microsoft Media Pro Antec Earthwatts 600w Antec 900 (modded) 
MouseMouse Pad
Logitech MX518 Steelpad 5L 
  hide details  
Reply
post #2 of 34
Um... I'm not that good at C programming (I'm just learning C), but my book had an example where you would have a "while" loop statement, and it would ask you to enter a number to proceed with the equation it solves, or press 0 to quit. So maybe you can use a "while" loop and have someone press "0" if they want to quit, or anything else to proceed.

Just an idea. I'm not especially good at this.
post #3 of 34
Use a do while loop that encases most of the program.
½
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD A64 3500+ Winchester DFI nF4 SLi-DR EVGA 7800GT OCZ 4000VX 
Hard DriveOptical DriveOSMonitor
Maxtor 300Gb 16Mb Buffer Spinney one XP Pro SOYO LCD 
KeyboardPowerCaseMouse
Broken Somewhat OCZ PowerStream 520W None Old 
Mouse Pad
Pad? AHAAHAHAH 
  hide details  
Reply
½
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD A64 3500+ Winchester DFI nF4 SLi-DR EVGA 7800GT OCZ 4000VX 
Hard DriveOptical DriveOSMonitor
Maxtor 300Gb 16Mb Buffer Spinney one XP Pro SOYO LCD 
KeyboardPowerCaseMouse
Broken Somewhat OCZ PowerStream 520W None Old 
Mouse Pad
Pad? AHAAHAHAH 
  hide details  
Reply
post #4 of 34
yeah, do a while statement that re-runs the program until the user answers no

while (userInput != y || userInput != Yes)
{
::call initial function::
}
Jesus PC v5.3
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-950 Gigabyte X58A-UD3R 5850 GSkill 1600 MHz 4x4GB 
Hard DriveOptical DriveOSMonitor
3x1200.12 500GB RAID 0, 2x2TB Deskstar RAID 1 Samsung Writemaster SATA Gentoo, Windows 7 x64 3x 21.5" Samsungs 
PowerCaseMouse
Thermaltake 750W RocketPwn G500 
  hide details  
Reply
Jesus PC v5.3
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-950 Gigabyte X58A-UD3R 5850 GSkill 1600 MHz 4x4GB 
Hard DriveOptical DriveOSMonitor
3x1200.12 500GB RAID 0, 2x2TB Deskstar RAID 1 Samsung Writemaster SATA Gentoo, Windows 7 x64 3x 21.5" Samsungs 
PowerCaseMouse
Thermaltake 750W RocketPwn G500 
  hide details  
Reply
post #5 of 34
Thread Starter 
Quote:
Originally Posted by The Hundred Gunner View Post
Um... I'm not that good at C programming (I'm just learning C), but my book had an example where you would have a "while" loop statement, and it would ask you to enter a number to proceed with the equation it solves, or press 0 to quit. So maybe you can use a "while" loop and have someone press "0" if they want to quit, or anything else to proceed.

Just an idea. I'm not especially good at this.
Thanks but I'm quite new at this too...

Quote:
Originally Posted by The Bartender Paradox View Post
Use a do while loop that encases most of the program.
What do you mean? :S
2011
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom X4 955 BE @ 3.2Ghz Gigabyte 880GA-UD3H XFX 6870 Dual Fan  4Gb G.Skill Ripjaw 1333Mhz 
Hard DriveOptical DriveCoolingOS
80Gb Seagate SATA LG DVD+ Zalman CNPS 9700 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Black 23" Full HD - LED Backlit Microsoft Media Pro Antec Earthwatts 600w Antec 900 (modded) 
MouseMouse Pad
Logitech MX518 Steelpad 5L 
  hide details  
Reply
2011
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom X4 955 BE @ 3.2Ghz Gigabyte 880GA-UD3H XFX 6870 Dual Fan  4Gb G.Skill Ripjaw 1333Mhz 
Hard DriveOptical DriveCoolingOS
80Gb Seagate SATA LG DVD+ Zalman CNPS 9700 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Black 23" Full HD - LED Backlit Microsoft Media Pro Antec Earthwatts 600w Antec 900 (modded) 
MouseMouse Pad
Logitech MX518 Steelpad 5L 
  hide details  
Reply
post #6 of 34
he's saying that you start the while statement in your main function, so that while userInput != y || userInput != yes, the program will continue executing until kingdom come

*edit* do you have your source?
Jesus PC v5.3
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-950 Gigabyte X58A-UD3R 5850 GSkill 1600 MHz 4x4GB 
Hard DriveOptical DriveOSMonitor
3x1200.12 500GB RAID 0, 2x2TB Deskstar RAID 1 Samsung Writemaster SATA Gentoo, Windows 7 x64 3x 21.5" Samsungs 
PowerCaseMouse
Thermaltake 750W RocketPwn G500 
  hide details  
Reply
Jesus PC v5.3
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-950 Gigabyte X58A-UD3R 5850 GSkill 1600 MHz 4x4GB 
Hard DriveOptical DriveOSMonitor
3x1200.12 500GB RAID 0, 2x2TB Deskstar RAID 1 Samsung Writemaster SATA Gentoo, Windows 7 x64 3x 21.5" Samsungs 
PowerCaseMouse
Thermaltake 750W RocketPwn G500 
  hide details  
Reply
post #7 of 34
Thread Starter 
Quote:
Originally Posted by FearMeansControl View Post
he's saying that you start the while statement in your main function, so that while userInput != y || userInput != yes, the program will continue executing until kingdom come

*edit* do you have your source?
Oh...nevermind all I had to do was main();

Lol thanks anyways guys.
2011
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom X4 955 BE @ 3.2Ghz Gigabyte 880GA-UD3H XFX 6870 Dual Fan  4Gb G.Skill Ripjaw 1333Mhz 
Hard DriveOptical DriveCoolingOS
80Gb Seagate SATA LG DVD+ Zalman CNPS 9700 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Black 23" Full HD - LED Backlit Microsoft Media Pro Antec Earthwatts 600w Antec 900 (modded) 
MouseMouse Pad
Logitech MX518 Steelpad 5L 
  hide details  
Reply
2011
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom X4 955 BE @ 3.2Ghz Gigabyte 880GA-UD3H XFX 6870 Dual Fan  4Gb G.Skill Ripjaw 1333Mhz 
Hard DriveOptical DriveCoolingOS
80Gb Seagate SATA LG DVD+ Zalman CNPS 9700 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Black 23" Full HD - LED Backlit Microsoft Media Pro Antec Earthwatts 600w Antec 900 (modded) 
MouseMouse Pad
Logitech MX518 Steelpad 5L 
  hide details  
Reply
post #8 of 34
Quote:
Originally Posted by Starholdest View Post
What do you mean? :S
int main();
{
//declare variables
//welcome message & other things you don't want repeated

do
{
//program that you want repeated
.
.
.
.
.

//ask if you want to repeat and store the answer in, oh lets say 'ans'

}
while(ans == y || ans == yes)

//all closing things

return 0;
}

Hopefully that helps. Ask more if you need it
½
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD A64 3500+ Winchester DFI nF4 SLi-DR EVGA 7800GT OCZ 4000VX 
Hard DriveOptical DriveOSMonitor
Maxtor 300Gb 16Mb Buffer Spinney one XP Pro SOYO LCD 
KeyboardPowerCaseMouse
Broken Somewhat OCZ PowerStream 520W None Old 
Mouse Pad
Pad? AHAAHAHAH 
  hide details  
Reply
½
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD A64 3500+ Winchester DFI nF4 SLi-DR EVGA 7800GT OCZ 4000VX 
Hard DriveOptical DriveOSMonitor
Maxtor 300Gb 16Mb Buffer Spinney one XP Pro SOYO LCD 
KeyboardPowerCaseMouse
Broken Somewhat OCZ PowerStream 520W None Old 
Mouse Pad
Pad? AHAAHAHAH 
  hide details  
Reply
post #9 of 34
hah! +rep for spending time on something silly like that, we all do it [not for teh lulz]!
Jesus PC v5.3
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-950 Gigabyte X58A-UD3R 5850 GSkill 1600 MHz 4x4GB 
Hard DriveOptical DriveOSMonitor
3x1200.12 500GB RAID 0, 2x2TB Deskstar RAID 1 Samsung Writemaster SATA Gentoo, Windows 7 x64 3x 21.5" Samsungs 
PowerCaseMouse
Thermaltake 750W RocketPwn G500 
  hide details  
Reply
Jesus PC v5.3
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-950 Gigabyte X58A-UD3R 5850 GSkill 1600 MHz 4x4GB 
Hard DriveOptical DriveOSMonitor
3x1200.12 500GB RAID 0, 2x2TB Deskstar RAID 1 Samsung Writemaster SATA Gentoo, Windows 7 x64 3x 21.5" Samsungs 
PowerCaseMouse
Thermaltake 750W RocketPwn G500 
  hide details  
Reply
post #10 of 34
Quote:
Originally Posted by Starholdest View Post
Oh...nevermind all I had to do was main();

Lol thanks anyways guys.
I would suggest what bartender posted rather than calling main again. Your way recursively calls main, which wastes memory. The program is trivial so it doesn't really matter, but bartender's post is better coding practice
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming