Help!!!

This is a discussion on Help!!! within the C++ Programming forums, part of the General Programming Boards category; wats wrong with this program #include <stdio.h> #include <stdlib.h> #include <iostream.h> int spp(); int buy(); int main() { char name[8]; ...

  1. #1
    Registered User mill1000's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Unhappy Help!!!

    wats wrong with this program



    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    int spp();
    int buy();

    int main()
    {
    char name[8];
    int sf = 1;
    int st = 1;
    int sp = 1;
    int se = 1;
    while(sf+st+sp+se-4>15)
    {
    cout<<"Enter your name(max 8 char.):";
    cin>>name;
    cout<<"You have 15 skill points you can add.\n";
    cout<<"Increase fighter skills by:";
    cin>>sf;
    cout<<"Increase trader skills by:";
    cin>>st;
    cout<<"Increase piolet skills by:";
    cin>>sp;
    cout<<"Increase engenier skills by:";
    cin>>se;
    if(sf+st+sp+se-4>15)
    {
    cout<<"Sorry you have more than 15 points put into your skills.\n";
    }
    else
    {
    spp();
    }
    }
    return 0;
    }




    int spp()
    {
    int sel;
    while (sel>5 || sel<1)
    {
    cout<<"1. Buy\n";
    cout<<"2. Sell\n";
    cout<<"3. Shipyard\n";
    cout<<"4. Warp\n";
    cout<<"5. Exit(game cannot be saved)\n";
    cout<<"Enter selection 1, 2, 3, 4 or 5: ";
    cin>>sel;
    if (sel>5 || sel<1)
    {
    cout<<"Error! No such input.\n";
    }
    else
    {
    }
    }
    switch(sel)
    {
    case 1:
    buy();
    break;
    case 2:
    break;
    case 3:
    break;
    case 4:
    break;
    case 5:
    exit;
    }
    return 0;
    }

    int buy()
    {
    int bought;
    int bays;
    int credit=2000;
    int pf;
    int bse;
    cout<<"You can buy food , water, clothes, ore, guns(which are illegal), medicine, machinery and narcotics(which are illegal too).\n";
    while (bse>8 || bse<1)
    {
    cout<<"1. Food 140-200\n";
    cout<<"2. Water-160\n";
    cout<<"3. Clothes-250\n";
    cout<<"4. Ore-500\n";
    cout<<"5. Guns-2,500\n";
    cout<<"6. Medicine-1,000\n";
    cout<<"7. Machinery-3,500\n";
    cout<<"8. Narcotics-6,000\n\n";
    cout<<"You have ";
    cout<<credit;
    cout<<" credits.\n\n";
    cout<<"Enter selection 1, 2, 3, 4, 5, 6, 7 or 8: ";
    cin>>bse;
    if (bse>8 || bse<1)
    {
    cout<<"Error! No such input.\n\n";
    }
    else
    {
    }
    }
    switch(bse)
    {
    case 1:
    {
    cout<<"At ";
    cout<<pf;
    cout<<" credits each, how many would you like to buy:";
    cin>>bought;
    bought+bays;
    if(bought*pf>credit)
    {
    cout<<"You don't have enough credits.\n";
    buy();
    }
    else
    {
    if(bays<=15)
    {
    cout<<bought;
    cout<<" canisters of food have been added in your holds.\n";
    spp();
    }
    else
    {
    cout<<"Sorry, you only have 15 bays.\n";
    buy();
    }
    }
    }
    break;
    case 2:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    }
    break;
    case 3:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    }
    break;
    case 4:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    }
    break;
    case 5:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    }
    break;
    case 6:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    }
    break;
    case 7:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    }
    break;
    case 8:
    {
    cout<<"How many would You like to buy:";
    cin>>bought;
    bays+bought;
    if(bays>15)
    {
    cout<<"Sorry, you only have 15 bays.\n";
    }
    else
    {
    }
    }
    break;
    }
    return 0;
    }

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    Please use "code tags" so your source code is more readable...

    --- what error messages do you get from your compiler..????

  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    it complies fine now, but i think you have a number of logic errors still left. changes are noted. also, if you want any sort of response around here, you should make this as easy as possible for use; that includes code tags and percise questions.

    Code:
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <iostream.h> 
    
    int spp(); 
    int buy(); 
    
    int main() 
    { 
    	char name[8]; 
    	int sf = 1, st = 1, sp = 1, se = 1; 
    	while((sf+st+sp+se-4) < 15) //change > to <
    	{ 
    	cout<<"Enter your name(max 8 char.):"; 
    	cin>>name; 
    	cout<<"You have 15 skill points you can add.\n"; 
    	cout<<"Increase fighter skills by:"; 
    	cin>>sf; 
    	cout<<"Increase trader skills by:"; 
    	cin>>st; 
    	cout<<"Increase piolet skills by:"; 
    	cin>>sp; 
    	cout<<"Increase engenier skills by:"; 
    	cin>>se; 
    		if((sf+st+sp+se-4) > 15) 
    		{ 
    			cout<<"Sorry you have more than 15 points put into your skills.\n"; 
    		} 
    		else 
    		{ 
    			spp(); 
    		} 
    	} 
    	return 0; 
    } 
    
    int spp() 
    { 
    	int sel; 
    	while (sel>5 || sel<1) 
    	{ 
    		cout<<"1. Buy\n"; 
    		cout<<"2. Sell\n"; 
    		cout<<"3. Shipyard\n"; 
    		cout<<"4. Warp\n"; 
    		cout<<"5. Exit(game cannot be saved)\n"; 
    		cout<<"Enter selection 1, 2, 3, 4 or 5: "; 
    		cin>>sel; 
    		if (sel>5 || sel<1) 
    		{ 
    			cout<<"Error! No such input.\n"; 
    		} 
    		else 
    		{ 
    		} 
    	}
    	switch(sel) 
    	{ 
    		case 1: buy(); 
    				break; 
    		case 2: break; 
    		case 3: break; 
    		case 4: break; 
    		case 5: break; //from exit to break

  4. #4
    Registered User mill1000's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Unhappy

    wats code tags

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21