| Code Apperentice (9) | |
|
I need help with my program, I don't understand why this does not work. The Content was too long, ill send the other part in another message Part 1 of Code: /-------------------- #include <iostream> //windows.h is for the Beep #include <windows.h> using namespace std; //-------------------- int add_10_nums(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) { //To add the 10 integers int t = 0; t = a + b + c + d + e + f + g + h + i + j; return t; } int times_2_nums(int a,int b) { int t=0; t = a*b; return t; } void main() { //Actual Lesson + a extras //Variables int x = 0,y = 0,z = 0,total = 0,q = 0,w = 0,e = 0,r = 0,u = 0,i = 0,b = 0,n = 0,m = 0,k = 0,t = 0,f = 0,p = 0,s = 0,v = 0; //User selects operation cout << "Would you like to add ten numbers or multiply 2 numbers or do a beep? 1 for adding 2 for multiplying and 3 for beep: "; cin >> r; if(r==1) { //User has to define if they want to add 2,3,4,5,6,7,8,9, or 10 numbers cout << endl << "Would you like to add 2,3,4,5,6,7,8,9, or 10 numbers, enter 2 for 2 num, etc: "; cin >> v; if(v==2) { //User has to define variables cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==3) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==4) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==5) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==6) cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "Enter sixth number:"; cin >> m; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==7) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "Enter sixth number:"; cin >> m; cout << endl << "Enter seventh number:"; cin >> t; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==8) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "Enter sixth number:"; cin >> m; cout << endl << "Enter seventh number:"; cin >> t; cout << endl << "Enter eighth number:"; cin >> f; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==9) There were many errors, but the one im confused with is the error, syntax error: else. I believe all my ifs and else ifs are correct, and it says im missing semicolons when I'm not, Please help | |
|
|
|
| Code Apperentice (9) | |
|
Second part of code: { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "Enter sixth number:"; cin >> m; cout << endl << "Enter seventh number:"; cin >> t; cout << endl << "Enter eighth number:"; cin >> f; cout << endl << "Enter ninth number:"; cin >> p; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } else if(v==10) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "Enter sixth number:"; cin >> m; cout << endl << "Enter seventh number:"; cin >> t; cout << endl << "Enter eighth number:"; cin >> f; cout << endl << "Enter ninth number:"; cin >> p; cout << endl << "Enter tenth number:"; cin >> s; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << f << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; //User has to confirm operation if(k==1) { //Now that variables are defined and operation is confirmed, add the variables total = add_10_nums(x,y,z,b,n,m,t,f,p,s); //Display the total cout << endl << "Total=" << total << endl << endl; } } } else if(r==2) { //User has to define the variables cout << "Enter first number to multiply:"; cin >> u; cout << "Enter second number to multiply:"; cin >> i; //Multiplying the two variables total = times_2_nums(u,i); //Displaying the total cout << endl << "Total=" << total << endl << endl; } else if(r==3) { //User has to define the variables for beep frequency + duration cout << "Enter beep frequency:"; cin >> w; cout << "Enter beep duration:"; cin >> e; Beep(w,e); } //User selects an operation again or terminates the program cout << endl << "Would you like to do a beep or adding or multiplication again? type 1 for a beep, 2 for adding and 3 for multiplication and 4 to finish:"; cin >> q; //Same coding as first time if (q==1) { cout << "Enter beep frequency:"; cin >> w; cout << "Enter beep duration:"; cin >> e; Beep(w,e); } else if (q==2) { cout << "Enter first number:"; cin >> x; cout << endl << "Enter second number:"; cin >> y; cout << endl << "Enter third number:"; cin >> z; cout << endl << "Enter fourth number:"; cin >> b; cout << endl << "Enter fifth number:"; cin >> n; cout << endl << "Enter sixth number:"; cin >> m; cout << endl << "Enter seventh number:"; cin >> t; cout << endl << "Enter eighth number:"; cin >> f; cout << endl << "Enter ninth number:"; cin >> p; cout << endl << "Enter tenth number:"; cin >> s; cout << endl << "The numbers you are about to add are:" << x << "," << y << "," << z << "," << b << "," << n << "," << m << "," << t << "," << y << "," << p << "," << s <<" if these are the numbers you want, type 1, else, type anything you want except 1 to cancel"; cin >> k; if(k==1) { total = add_10_nums(x,y,z,b,n,m,t,y,p,s); cout << endl << "Total=" << total << endl << endl; } } else if (q==3) { cout << "Enter first number to multiply:"; cin >> u; cout << "Enter second number to multiply:"; cin >> i; total = times_2_nums(u,i); cout << endl << "Total=" << total << endl << endl; } else if (q==4) { } } | |
|
|
|
| Code Apperentice (9) | |
| This is a Console Application | |
|
|
|
| newbieg (173) | |||
|
There were at least 2 problems; Your first line needs two //, not just one your else if(v==6) needs a { after it. After fixing those your program will at least get to the console. You should probably give instructions on how to get a beep, the frequency needs to be between 37 through 32,767, and the duration is measured in milliseconds (so they should put in a high number) Just a suggestion, but this could have been a much shorter code if you learn how to use arrays and loops. If you learn those then this could be done in under 170 lines of code (and that's my high guess). I know you included the <windows.h> header, but it would have been better if you posted this in the beginner's forum, you'd have been helped sooner. Here's an example of a loop that uses the beep function to make an RPG-style noise.
| |||
|
Last edited on
|
|||
| Code Apperentice (9) | |
| Thanks! I will post in the beginners forum in future posts(If I'm still one) | |
|
|
|
| newbieg (173) | |
| No problem. Hey though, I wasn't trying to be rude or anything, Beginner's forum is where I post most of my questions, It just gets higher traffic and your questions really will be answered faster there. | |
|
|
|
| Code Apperentice (9) | |
|
don't worry, i didn't find it as rude. Youdid repliy quite fast... 3 hours after my post, I appreciate that | |
|
|
|