how can i combine this 2 c++ in to 1 c++ prog thx for the help the first one Code: #include <iostream> #include <conio.h> using namespace std; main () { int a,b,sum,dif,prod,quot; cout << " \n Enter the First number: "; cin >> a; cout << " \n Enter the Second number: "; cin >> b; sum = a + b; dif = a - b; prod = a * b; quot = a / b; cout << " \n The sum is: "<< sum ; cout << " \n The difference: "<< dif ; cout << " \n The Product is: "<< prod; cout << " \n The quotient is: "<< quot; cout << " \n \n \n "; return main(); getch(); } and this one Code: #include <iostream> #include <conio.h> using namespace std; main() { int a, b; char response; cout << "*************************************** \n"; cout << " \t INPUT THE DAY NUMBER: " ; cin >> a; if (a==1) cout << " \t THE DAY IS MONDAY\n " ; if (a==2) cout << " \t THE DAY IS TUESDAY\n " ; if (a==3) cout << " \t THE DAY IS WEDNESDAY\n " ; if (a==4) cout << " \t THE DAY IS THURSDAY\n " ; if (a==5) cout << " \t THE DAY IS FRIDAY\n " ; if (a==6) cout << " \t THE DAY IS SATURDAY\n " ; if (a==7) cout << " \t THE DAY IS SUNDAY\n " ; return main(); getch(); } into one prog
@shizzle08 : Why do both your programs end with "return main();" ? That will let your program fall into an infinite loop and you have to manually break your program's execution. If you wanted to repeat the portion inside main(), then you can use some other techniques like while(<some condition>) or for(<something else>) etc... and always return 0;
(1) Put both main() functions into a new file. (2) Rename both main() functions to something appropriate. (3) Write a new main() function to call the two functions in whatever order you see fit. Saswat is talking about this line of code: Code: return main(); This is wrong. I don't know where you got the idea that you should include the function name in a return statement. A return statement should return no value at all, i.e. Code: return; OR should return some suitable value: Code: int func() // returns an integer { int x; // ...some code that calculates x... return x; } A return statement isn't necessary at the end of a function as the function will return once it hits the closing brace anyway: Code: void func() { // ...some code... return; // this line is pointless // (unless it was a conditional return, and you have more code here) }
this is how it should be sir... then when they chose 1 the basic calculator must be seem lyk this and then it will ask them
sorry for double posting i can't see the edit button @sir xpi0t0s can u make me a c++ that has basic calculator,number of days. so that i cant see how to do it thanks
No, the idea of you being given assignments is that you learn by figuring this stuff out for yourself, using the course notes you've already been given. All you need to solve this is some input, output and some if statements, all of which you already know from the code you've already written. So start by displaying the menu selections, reading an option from the user and displaying it back to them. Make sure that works, then start adding code to process that input; if it equals 1 then call a function that reads the values from the user, processes them and prints some output. Make sure that works OK, then add more code to handle the other options.
Finish.) one last thing after they use one of the following a question will prompt asking if they want to use it again? 'Y' or 'N' and if 'Y' then it will return to Int Main () if 'N' it will close? hehe PHP: #include <iostream>#include <conio.h>using namespace std;void Calc();void Days();void Post();void Circle();void Rectangle();void Square();void Sphere();int main(){ int k; cout << "1 > Basic Calculator." << endl; cout << "2 > Number of Days." << endl; cout << "3 > Postive/ Negative." << endl; cout << "4 > Area and Cirumference of a Circle." << endl; cout << "5 > Area of Rectangle." << endl; cout << "6 > Area Square." << endl; cout << "7 > Volume of Sphere." << endl; cin >> k; switch(k) { case 1: Calc(); case 2: Days(); case 3: Post(); case 4: Circle(); case 5: Rectangle(); case 6: Square(); case 7: Sphere(); default: cout << "Wrong input" << endl; } return 0;}void Calc(){int a,b,sum,dif,prod,quot;cout << " \n Enter the First number: ";cin >> a;cout << " \n Enter the Second number: ";cin >> b;sum = a + b;dif = a - b;prod = a * b;quot = a / b;cout << " \n The sum is: "<< sum ;cout << " \n The difference: "<< dif ;cout << " \n The Product is: "<< prod;cout << " \n The quotient is: "<< quot;cout << " \n \n \n ";getch();} void Days(){int a, b,;cout << "*************************************** \n";cout << " \t INPUT THE DAY NUMBER: " ;cin >> a;if (a==1)cout << " \t THE DAY IS MONDAY\n " ;if (a==2)cout << " \t THE DAY IS TUESDAY\n " ;if (a==3)cout << " \t THE DAY IS WEDNESDAY\n " ;if (a==4)cout << " \t THE DAY IS THURSDAY\n " ;if (a==5)cout << " \t THE DAY IS FRIDAY\n " ;if (a==6)cout << " \t THE DAY IS SATURDAY\n " ;if (a==7)cout << " \t THE DAY IS SUNDAY\n " ;getch();} void Post(){int a,rush;cout <<"************************************\n";cout << "\t \"Enter a number\": ";cin >> a;rush = a%2;if (a<0)cout << "\t \"the number is negative\" \n";elseif (a>0)cout << "\t \"the number is positive\" \n";if (rush==0)cout << "\t \"the number is even\" \n";elsecout << "\t \"the number is odd\" \n";getch();}void Circle(){ float a,c,pi,r; cout << " Enter the Radius: "; cin >> r; pi = 3.14; a = pi*r*r; c = 2*pi*r; cout << " \nThe area is: "<< a; cout << " \nThe circumference is: "<<c; getch();}void Rectangle(){ float a,h,w; cout << " Enter The Hieght: "; cin >> h; cout << " Enter The Width: "; cin >> w; a = 0.5*h*w; cout << "The area is: "<<a; getch(); }void Square(){ float s,a; cout << " Enter the side: "; cin >> s; a = s * s; cout << " The answer is : "<< a; getch();}void Sphere(){ float r,pi,sp; cout << " Enter The Radius: "; cin >> r; pi = 3.1416; sp = (4/3)*pi*r*r*r; cout << " the Volume is: "<< sp; getch (); }
Not sure if that's a question; if it is, just wrap the contents of main in a for(; block and add a menu option, e.g. 8 Quit, and make case 8 return 0; Then the program will quit when they select 8; this is better than having a separate Y/N prompt to continue or quit. Think about the design, if you have several tasks to perform with the program, you would want to run them one after the other then select quit when you're done; you don't want to be asked whether or not to continue after every operation.