|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
C++ restart program help! :)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#11 (permalink) | ||||||||||||||
|
Mmmm! Toast!
|
Quote:
Code:
int main(int argc, char **argv) {
do {
/* your program */
} while (again);
return 0;
}
|
||||||||||||||
|
|
|
|
#12 (permalink) | |||||||||
|
Overclocker
|
Quote:
Having to scroll to the bottom of a while loop to see the condition is annoying. Also why do you keep a bracket on the same line as int main()? It makes it harder to count brackets when your compiler gets angry with you for having too many or too few end brackets. What I am doing in a program that I have been working for the past year is: Code:
while (answer != 0)
{
cout<<" MAIN MENU n";
cout<<" quit 0 n";
cout<<" Read in raw to input 1 n";
cout<<" Read in 3-D raw to input 2 n";
cout<<" Write input image to file 3 n";
cout<<" Write 3-D output image to file 4 n";
cout<<" Write output image to file 5 n";
cout<<" Zoom image with pixel replication 6 n";
cout<<" Create a histogram 7 n";
cout<<" Do Linear Interpolation 8 n";
cout<<" Do Bilinear Interpolation 9 n";
cout<<" Do Trilinear Interpolation 10n";
cout<<" Generate circle contrast detail 11n";
cout<<" Generate square contrast detail 12n";
cout<<" Add noise to the image 13n";
cout<<" Use a convolution filter 14n";
cout<<" Put processed image into input 15n";
cout<<" Shrink Image 16n";
cout<<" Use Image calculator 17n";
cout<<" Median Filter 18n";
cout<<" Average Filter 19n";
cout<<" Unsharp Mask 20n";
cout<<" Bit Reduction 21n";
cout<<" Generate hidden image(raw array) 22n";
//cout<<" Fast Fourier Transform 23n";
cout<<" Generate spoke image 24n";
cout<<" Generate line pair image 25n";
cout<<" Use Tile filter 26n";
cout<<" Read in Bitmap 27n";
cout<<" Change Characteristic Curve 28n";
if (1 == answer)
{
func(arguments);
}
else if (2 == answer)
{
func(arguments);
}
//etc....
}
__________________
My next computer (Silent OCer)
Last edited by A Legend of Sorts : 02-20-08 at 05:04 PM. |
|||||||||
|
|
|
|
|
#13 (permalink) | ||||||||||||||
|
Every base is base 10
|
Quote:
The bracket thing is just style. Keeping it on the same line gives a more compact look.
|
||||||||||||||
|
|
|
|
#14 (permalink) | |||||||||||||
|
Mmmm! Toast!
|
[quote=A Legend of Sorts;3425532]bah, while(condition){code} > do{code}while(condition);
Having to scroll to the bottom of a while loop to see the condition is annoying. Also why do you keep a bracket on the same line as int main()? It makes it harder to count brackets when your compiler gets angry with you for having too many or too few end brackets. QUOTE] do..while does it once without the initial test or "fooling" the while into thinking something already happened. I put my braces there because that's they way I've done it since 1990.
|
|||||||||||||
|
|
|
|
#15 (permalink) | ||||||||||||||
|
AMD Overclocker
|
Quote:
![]()
__________________
Volkswagen Enthusiasts of OCN Aumotocnic "An unfortunate member of the overclock.net insomnia club" Quebec Overclockers - 8019 in 3dMark06s939 Manny 4600+ @ 2809Mhz @ 1.425V (9 hours Orthos blend test stable - 24/7 Usage) - http://valid.x86-secret.com/show_oc.php?id=289741 @ 2945Mhz @ 1.45V - http://valid.x86-secret.com/show_oc.php?id=276669
|
||||||||||||||
|
|
|
|
#16 (permalink) | ||||||||||||||
|
Off By 340 Undecillion
|
Quote:
int counter = 0; while(counter <= 4) { ++counter; } In this code example the while loop will keep incrementing counter by 1 as long as counter is less than or equal to 4. So this loop will run 5 times and counter will be equal to 5 at the end of this loop. (it loops one more time when counter is 4 because our loop condition is still true at 4)
__________________
Congratulations! You have found the secret text! You get a cookie.
|
||||||||||||||
|
|
|
|
#17 (permalink) | |||||||||||||||
|
AMD Overclocker
|
Quote:
Code:
#include <iostream>
#include <string>
using namespace std;
float convert_money(float, float, char);
char quit;
float money;
char tax_option;
float tax_number;
bool restart();
float var_return[4];
int main ()
{
cout << "How much money do you want to convert?: ";
cin >> money;
cout << "Do you want to calculate tax? (y/n): ";
cin >> tax_option;
if(tax_option == 'y')
{
cout << "What % is the tax?: ";
cin >> tax_number;
}
convert_money(money, tax_number, tax_option);
cout << "nnDo you want to restart? (y/n): ";
cin >> quit;
if(quit == 'y')
{
return 0;
}
else
{
system("cls");
main();
}
}
float convert_money (float a, float b, char c)
{
var_return[0] = (a * 0.984348);
var_return[1] = (a / 0.984348);
cout << "nConvert:n" << money << " CAD = " << var_return[0] << " US";
cout << "n" << money << " US = " << var_return[1] << " CAD";
if(c == 'y')
{
var_return[2] = ((a * (b / 100)) + a);
cout << "nnTax calculation with " << b << "% tax:n";
cout << money << " = " << var_return[2];
}
}
Code:
if(tax_option == 'y' || tax_option == 'yes') Quote:
Elliott
__________________
Volkswagen Enthusiasts of OCN Aumotocnic "An unfortunate member of the overclock.net insomnia club" Quebec Overclockers - 8019 in 3dMark06s939 Manny 4600+ @ 2809Mhz @ 1.425V (9 hours Orthos blend test stable - 24/7 Usage) - http://valid.x86-secret.com/show_oc.php?id=289741 @ 2945Mhz @ 1.45V - http://valid.x86-secret.com/show_oc.php?id=276669
|
|||||||||||||||
|
|
|
|
#18 (permalink) | |||||||||||||
|
Off By 340 Undecillion
|
A char type variable only stores one character. When you try to check tax_option is equal to 'yes' the compiler gets confused because tax_option should only be one character and you tried to compare it to three. There is other ways to get it to read the whole 'yes', but it probably will be easier just to have it check for y, or possibly for Y as well.
__________________
Congratulations! You have found the secret text! You get a cookie.
|
|||||||||||||
|
|
|
|
#19 (permalink) | ||||||||||||||
|
AMD Overclocker
|
Quote:
__________________
Volkswagen Enthusiasts of OCN Aumotocnic "An unfortunate member of the overclock.net insomnia club" Quebec Overclockers - 8019 in 3dMark06s939 Manny 4600+ @ 2809Mhz @ 1.425V (9 hours Orthos blend test stable - 24/7 Usage) - http://valid.x86-secret.com/show_oc.php?id=289741 @ 2945Mhz @ 1.45V - http://valid.x86-secret.com/show_oc.php?id=276669
|
||||||||||||||
|
|
|
|
#20 (permalink) | ||||||||||||||
|
Off By 340 Undecillion
|
Quote:
You can do it with just a char. Yes starts with a y. When you cin >> tax_option it writes just the first letter of what ever was entered to tax_option. So if the input is yes or y tax_option will still get the value y. Of course if the user entered yes, the e and the s would still be in the input buffer. Since you are restarting the program it would probably be beneficial to clear the input buffer. You can do that by using cin.ignore(5, '\n') where the 5 indicates how many characters you would like to ignore, and the '\n' is alternatively what character you would like to stop on. So cin.ignore(5, '\n') says ignore the next five characters or up until the newline character, which ever comes first. Hope that helps ![]()
__________________
Congratulations! You have found the secret text! You get a cookie.
|
||||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|