Hi I have created a program but i'm stuck in one thing that if press 1 then the new windows is open and the existing one is close and also how to return to main menu. how to open every program in new window with exiting the first window...
\\ Here is my program
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main(){
int a;
a = 1, 2;
{
cout << "Press 1 for selection program:\n";
cout << "Press 2 for looping:\n";
cout << "Press 3 to exit program:\n";
cout << "Enter your choice:\n";
}
cin >> a;
{
if (a == 1)
{
cout << "Press 1 Pass or Fail\n";
cout << "Press 2 Even or Odd\n";
cout << "Press 3 Leap year\n";
cout << "Press 4 Salary or Grade\n";
}
}
if (a == 1)
{
int marks;
cout << "Enter your Marks\n";
cin >> marks;
if (marks >= 60)
{
cout << "Congratulations you have passed\n";
}
else
{
cout << "You're failed\n";
}
}
if (a == 2)
{
int integer;
cout << "Please enter an integer"
<< endl;
cin >> integer;
if (integer % 2 == 0)
cout << integer << " is even "
<< endl;
else
cout << integer << " is odd "
<< endl;
return 0;
}
if (a == 3)
{
int year;
cout << "\n Enter the year = ";
cin >> year;
if (year % 4 == 0 || year % 400 == 0 || year % 100 == 0)
cout << "this is a leap year" << endl;
else
cout << "this is not a leap year" << endl;
if (a == 4)
{
float salary, bonus;
int grade;
cout << "Enter your salary:\n";
cin >> salary;
cout << "Enter your grade:\n";
cin >> grade;
if (grade > 50)
bonus = salary * 70 / 100;
else
bonus = salary * 35 / 100;
salary = salary + bonus;
cout << "Your total salary is Rs.\n";
cout << salary;
}
}
if (a == 2)
{
cout << "Press 1 for Table program\n";
cout << "Press 2 Factorial\n";
cout << "Press 3 Sentinel loops\n";
cout << "Press 4 Main menu\n";
}
if (a == 1)
{
int n;
cout << "Enter an integer: ";
cin >> n;
for (int i = 1; i <= 10; ++i) {
cout << n << " * " << i << " = " << n*i << endl;
n = n + 1;
}
}
if (a == 2)
{
long int n, c, f;
c = 1;
f = 1;
cout << "Enter a number :\n";
cin >> n;
while (c <= n)
{
f = f*c;
c = c + 1;
}
cout << "Factorial of\n" << n << "is" << f << endl;
}
if (a == 3)
{
int n;
n = 1;
while (n != -2)
{
cout << "Hello Pakistan!!!\n";
cout << "Do you want to continue:\n";
cin >> n;
}
}
if (a == 4)
{
cout << "Here you go to main window";
}
system("pause");
}
#include <iostream>
#include <stdio.h> //dont mix cpp code with C libs
#include <cstdlib>
usingnamespace std;
int main()
{
int a;
a = 1, 2; //what does this mean?
//{ //why is this brace here ...
cout << "Press 1 for selection program:\n";
cout << "Press 2 for looping:\n";
cout << "Press 3 to exit program:\n";
cout << "Enter your choice:\n";
//} //and here...
cin >> a;
//{ // DO YOU REALLY KNOW WHAT "curly braces" ARE USED FOR???
if (a == 1)
{
cout << "Press 1 Pass or Fail\n";
cout << "Press 2 Even or Odd\n";
cout << "Press 3 Leap year\n";
cout << "Press 4 Salary or Grade\n";
//}
//You have to get the input.
//reason why you always get "you failded".
cin>>a;
//}
if (a == 1)
{
int marks;
cout << "Enter your Marks\n";
cin >> marks;
if (marks >= 60)
{
cout << "Congratulations you have passed\n";
}
else
{
cout << "You're failed\n";
}
}
if (a == 2)
{
int integer;
cout << "Please enter an integer"<< endl;
cin >> integer;
if (integer % 2 == 0)
cout << integer << " is even "<< endl;
else
cout << integer << " is odd "<< endl;
//DO YOU REALLY WANT TO QUIT THE PROGRAM HERE??
return 0;
}
if (a == 3)
{
int year;
cout << "\n Enter the year = ";
cin >> year;
if (year % 4 == 0 || year % 400 == 0 || year % 100 == 0)
cout << "this is a leap year" << endl;
else
cout << "this is not a leap year" << endl;
}
if (a == 4)
{
float salary, bonus;
int grade;
cout << "Enter your salary:\n";
cin >> salary;
cout << "Enter your grade:\n";
cin >> grade;
if (grade > 50)
bonus = salary * 70 / 100;
else
bonus = salary * 35 / 100;
salary = salary + bonus;
cout << "Your total salary is Rs.\n";
cout << salary;
}
}
if (a == 2)
{
cout << "Press 1 for Table program\n";
cout << "Press 2 Factorial\n";
cout << "Press 3 Sentinel loops\n";
cout << "Press 4 Main menu\n";
//get input
cin>>a;
if (a == 1)
{
int n;
cout << "Enter an integer: ";
cin >> n;
for (int i = 1; i <= 10; ++i) {
cout << n << " * " << i << " = " << n*i << endl;
n = n + 1;
}
}
if (a == 2)
{
longint n, c, f;
c = 1;
f = 1;
cout << "Enter a number :\n";
cin >> n;
while (c <= n)
{
f = f*c;
c = c + 1;
}
cout << "Factorial of\n" << n << "is" << f << endl;
}
if (a == 3)
{
int n;
n = 1;
while (n != -2)
{
cout << "Hello Pakistan!!!\n";
cout << "Do you want to continue:\n";
cin >> n;
}
}
if (a == 4)
{
cout << "Here you go to main window";
}
}
if(a == 3)
{
cout<<"You choosed to quit"<<endl;
cout<<"Bye..."<<endl<<endl;
}
system("pause");
return 0;
}
the new windows is open and the existing one is close and also how to return to main menu