Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

New to programming, this should be an easy one!

I'm just starting to learn programming, and I ran in to a problem very early in my program. The first thing that I prompt the user for is the month, and that works fine. However it doesn't keep working after that, instead of just asking the user for the number of cookies made, it outputs the messages asking for the next 3 variables and then completes, so no other variables are entered. I'm stumped and I'm hoping that you can help me to get over this first obsticle so that I can continue working on my program.

code:

[code]#include
using namespace std;

int main()
{
int month;
int cook_made;
int reg_price;
int dis_price;

cout << "Enter the first three characters of the month: ";
cin >> month;
cout << "Enter the number of cookies made: ";
cin >> cook_made;
cout << "Enter the regular price for a box of cookies: ";
cin >> reg_price;
cout << "Enter the discount price for a box of cookies: ";
cin >> dis_price;

return (0);
}[/code]

and what I get when I run the program:

bash-3.00$ ./a.out
Enter the first three characters of the month: Dec
Enter the number of cookies made: Enter the regular price for a box of cookies: Enter the discount price for a box of cookies: bash-3.00$

Comments

  • formitzbsdformitzbsd Posts: 2Member
    The reason your program is exiting is because you are asking for the first 3 letters of a month. You declared month as a type int and that will not accept characters. You need to change

    int month;

    to

    string month;

    and it will work as intended.
  • formitzbsdformitzbsd Posts: 2Member
    The reason your program is exiting is because you are asking for the first 3 letters of a month. You declared month as a type int and that will not accept characters. You need to change

    int month;

    to

    string month;

    and it will work as intended.
  • ahmedcabahmedcab Posts: 2Member
    your problem is that you use the int type for month when you should use the string type or the char array type
    i have a tutorial on data types in my youtube channel

    it will show you the difference between the type
    ps: i'm not a native english speaker so my pronuncation is not very good.
  • ahmedcabahmedcab Posts: 2Member
    your problem is that you use the int type for month when you should use the string type or the char array type
    i have a tutorial on data types in my youtube channel

    it will show you the difference between the type
    ps: i'm not a native english speaker so my pronuncation is not very good.
Sign In or Register to comment.