Unlimited using

I am trying to do a program , witch open web-sites . But i have a problem on it .

I can't configure how to make this code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cstdlib>
#include <iostream>


using namespace std;

int main()
{
  int site;                       
  
  cout<<"Desired web-sites :\n";
  cout<<"1- Facebook\n";
  cout<<"2- Google\n";
  cout<<"3- EUHackers Official Site\n";
  cout<<"4- XxX Eagles XxX Official Site\n";
  cout<<"Push one of the disred numbers then press enter to open it\n";  
  cout<<" \n";
  cout<<" \n";
  cout<<"Your desired web-site number is : ";
  cin>> site;  
  cin.ignore();                  
  if ( site == 1 ) {            
        system("START http://www.cplusplus.com/forum/beginner/88318/");
        cout<<" \n";
        cout<<"Website has been open succesfully!";
        cout<<" \n\n";
        cout<<"Please input another number to continue : ";
  }
     else if( site == 2 ) {           
        system("START http://www.cplusplus.com/forum/beginner/88318/");
        cout<<" \n";
        cout<<"Website has been open succesfully!";
        cout<<" \n\n";
        cout<<"Please input another number to continue : ";
  } 
     else if ( site == 3 ) {
        system("START http://www.cplusplus.com/forum/beginner/88318/");
        cout<<" \n";
        cout<<"Website has been open succesfully!";
        cout<<" \n\n";
        cout<<"Please input another number to continue : ";
  }
     else if( site == 4 ) {
        system("START http://www.cplusplus.com/forum/beginner/88318/");
        cout<<" \n";
        cout<<"Website has been open succesfully!";
        cout<<" \n\n";
        cout<<"Please input another number to continue : ";
  }
     else {
       cout<<" \n\n\n";
       cout<<"You have entred invalid number.\n";
       cout<<"Please enter another VALID number : ";
  }
  cin.get();
}


When i press a number , it open the page well , but if i press another number for second time , it get closed . Help me with this please :(
Last edited on
> but if i press another number for second time , it get closed .

You need a loop of some kind to go back and open the next site.
Something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

int main()
{
    // ...
    int site ;
    do
    {
        std::cout << "enter one of the numbers (or -1 top quit): " ;
        while( !( std::cin >> site ) )
        {
            std::cout << "please enter a number: " ;
            std::cin.clear() ;
            std::cin.ignore(1000,'\n') ;
        }
        switch( site )
        {
            case 1 :
                /* open site 1 */
                break ;

            case 2 :
                /* open site 2 */
                break ;
            // etc ..
        }
    } while( site != -1 ) ;
}

Can you put it on the code please ?
> Can you put it on the code please ?

I suppose I can; but then you wouldn't be learning anything, would you?

Make an attempt to do it on your own; if you encounter difficulties, post a question and someone here would help you out.
I fixed all of them . The problem is only at :

The first time i wanna open a web-site nothing happens , it only happen at the second time ..
Last edited on
> The first time i wanna open a web-site nothing happens ,
> it only happen at the second time ..

Difficult to say why that should happen, without having a look at the code.
I have fixed all things , i just want an error message when you don't put
one of the numbers from 1 to 5 ..

Here code is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <cstdlib>
#include <iostream>


using namespace std;

int main()
{
  int site ;
  cout<<"Auto opener :\n";
  cout<<"1- Garena Plus download\n";  
  cout<<"2- DotA 6.77 changelogs\n";
  cout<<"3- DotA 6.77 download\n";
  cout<<"4- Warcraft 1.26 patch download\n";
  cout<<"5- Ven.detta official site\n\n";
  cout<<"Push one of the desired numbers then press enter to open it\n";  
  cout<<" \n";
  cout<<" \n";
  do
    {                     
        std::cout << "Please enter one of the numbers to continue or -1 to quit: ";
        while( !( std::cin >> site ) )
        {
            std::cout << "You have entred an invalid character !\n\n" ;
            std::cout << "Please enter one of the numbers to continue or -1 to quit: ";
            std::cin.clear() ;
            std::cin.ignore(1000,'\n') ;
        }
        switch( site )
        {
                case 1 : 
                     system("start http://universal-downloader.en.softonic.com/95000/95079/ud_200/SoftonicDownloader_for_garena.exe");
                     cout<<" \n";
                     cout<<"Website has been open succesfully!";
                     cout<<" \n\n";
                     break ;
                     
                case 2 : 
                     system("start http://www.playdota.com/changelogs/6.77");
                     cout<<" \n";
                     cout<<"Website has been open succesfully!";
                     cout<<" \n\n";  
                     break ;
                case 3 :                      
                     system("start http://static.getdota.com/maps/eng/DotA%20v6.77.w3x");
                     cout<<" \n";
                     cout<<"Website has been open succesfully!";
                     cout<<" \n\n";
                     break ;
                case 4 :
                     system("start http://ftp.blizzard.com/pub/war3x/patches/pc/War3TFT_126a_English.exe");
                     cout<<" \n";
                     cout<<"Website has been open succesfully!";
                     cout<<" \n\n";
                     break ;
                case 5 :
                     system("start http://ven-detta.tk");
                     cout<<" \n";
                     cout<<"Website has been open succesfully!";
                     cout<<" \n\n";
                     break ;
        }                 
   } while( site != -1 ) ;
}
Last edited on
Any solution please ?
> i just want an error message when you don't put one of the numbers from 1 to 5 ..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        switch( site )
        {
                case 1 : 
                     // ... 
                     break ;

                case 2 : 

                     // etc upto case 5

               case -1 :
                    break ;

               default:
                     // print error message 
                     // the number entered is not one of the numbers from 1 to 5 .. or -1
        }                 
   } while( site != -1 ) ;
Yes thanks , it helped me , but i have a question , is there any way to change the quit command ( -1 ) to something else like "quit" or "exit" ?
You can add an additional option "exit" to the program menu and then use system("exit").

1
2
3
4
5
6
7
8
9
                case 8 :
                     system("exit");
                     break;
                default :
                     cout<<"\n|--|The number you entred is wrong !|--|\n\n";
                     break ;
        }                 
   } while( site != -1 ) ;
}


IDK if you meant this , this is what i done and when i press 8 nothing happen , it just ask like normal to put another number in it ( NOT WRONG NUMBER ERROR )
It's because you are still in the loop. You could have an exit flag, say

1
2
 
int exit = 8; 


and then instead of

1
2
 
while( site != -1 )


you use

1
2
 
while( site != exit )


> is there any way to change the quit command ( -1 ) to something else like "quit" or "exit" ?

There is; you need to accept the input as a sequence of chars - a std::string - not as an integer. And then examine what that input string contains.

Topic archived. No new replies allowed.