Source code problem.....

i am a new learner of C++ n just study it based on book n practising.....

I try to do something but it didn't do what I want.... What is the problem in my source code.....

My planning is.... when we enter letter 'Y' the program will continuing...
when I enter 'N', the program will go to starting (mula)
when I put enter others.....It will asked the question to input Y and N again.....

*******************************************************************************

#include <stdio.h>


void main()
{

//declaration
int nmin, agree, Y, y, N, n;
float CA, CA1, CA2, CB;
Y=y=1;
N=n=0;


//introduction about the program
printf("WELCOME TO WEEZ STUDIO CREATIVE WORLD.\nThis program will analyze two different rate plans for cellular phone access.");
printf("To start,enter the number of minutes that you plans on using in a month\n\n");


//starting of 7525164

mula:
printf("Enter number of minutes you plan to use each month:\n");
scanf("%d",&nmin);
printf("\n\nYou entered %d minutes\n",nmin);


//selection part

yesno:
printf("Enter Y to continue or N to change the number of minute.");
scanf("%s",&agree);


//selection controll


if(agree==1)
goto continued;


else if(agree==0)
goto mula;


else goto yesno;




//continuing the program... if answer yes
continued:

//formula

CA1 = 25;
CA2 = 25+((nmin-60)*0.25);
CB = nmin*0.5;



//Plan A rate controll


if(nmin>0)
CA = CA1;


else if(nmin>60)

CA = CA2;


//if -ve input or rubbish input

else printf("Invalid input. Program will now terminate.");
goto end;



//Display minute

printf("For %d minutes usage per month,\n",nmin);
printf("Cost of rate for Plan A = $ %.2f\n",CA);
printf("Cost of rate for Plan B = $ %.2f\n",CA);



//Suggestion from the system

//Suggestion from the system

CA<CB ? printf("Plan A is the better choice\n\n"):printf("Plan B is the better choice\n\n");


end://end part of the system......closing
printf("Thank you for using our program.\n\n");

//SYSTEM SUCCESS....
}
Use int main().
Don't use goto, it isn't needed here.

Fix that first.
this is not well coded. it's just a demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main(int argc, char* argv[]) {
    char option = 'y';

    while(option=='y') {
        option = 'x';
        cout << "do someting here\n";

        while(!(option=='y' || option=='n')) {
            cout << "Do you want to try again? Y/N ";
            cin >> option;
        }
    }
    return 0;
}

edit: your doing your code the C way not C++
Last edited on
One of the things I noticed at first glace is in the next section of code:

1
2
3
4
5
//selection part

yesno:
printf("Enter Y to continue or N to change the number of minute.");
scanf("%s",&agree);


you declared 'agree' variable as integer type and when u try to read it whith scanf you specified the wrong format:
printf("Enter Y to continue or N to change the number of minute.");
scanf("%s",&agree);

here you are trying to get a string from the input (format %s) and store it in an int variable (int agree;). It should be like this:

scanf ("%d", &agree); or scanf("%i", &agree); either way it reads a decimal number.
Hope this helps!!!
Topic archived. No new replies allowed.