Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Shopping prog

Finished making your own program (thats not part of the practicing forums) ? Show it off here

Shopping prog

Postby ShadowTH on Sun Oct 04, 2009 11:55 pm

Heres my little program that lets you buy stuff lawl.
What do you all think?? =]

Code: Select all
#include <iostream>
using namespace std;

//Checkout thing by Aaron McNuggets

bool exitprog = false;
int beer_int = 0;
int cake_int = 0;
int bannana_int = 0;
int apple_int = 0;
int xbox_int = 0;
int ps_int = 0;
int wii_int = 0;
int dc_int = 0;
int price = 0;

int checkout()
{
    while ( beer_int > 0 ) {  price+=3; beer_int--; }
    while ( cake_int > 0 ) {  price+=5; cake_int--; }
    while ( bannana_int > 0 ) {  price+=1; bannana_int--; }
    while ( apple_int > 0 ) {  price+=1; apple_int--; }
    while ( xbox_int > 0 ) {  price+=400; xbox_int--; }
    while ( ps_int > 0 ) {  price+=650; ps_int--; }
    while ( wii_int > 0 ) {  price+=250; wii_int--; }
    while ( dc_int > 0 ) {  price+=150; dc_int--; }
    cout << "Total price: $" << price << endl;
    cout << "Thank you come again!" << endl;
    cout << "Press enter to restart :)";
    price = 0;
    cin.get();
    cin.get();
}

int what_you_have_bought(int shop)
{
     if (shop == 1) { beer_int++; }
     if (shop == 2) { cake_int++; }
     if (shop == 3) { bannana_int++; }
     if (shop == 4) { apple_int++; }
     if (shop == 5) { xbox_int++; }
     if (shop == 6) { ps_int++; }
     if (shop == 7) { wii_int++; }
     if (shop == 8) { dc_int++; }
     system("cls");
     cout << "(1) - Beer's ($3)         = " << beer_int << endl;
     cout << "(2) - Cake's ($5)         = " << cake_int << endl;
     cout << "(3) - Bannana's ($1)      = " << bannana_int << endl;
     cout << "(4) - Apples's ($1)       = " << apple_int << endl;
     cout << "(5) - Xbox 360's ($400)   = " << xbox_int << endl;
     cout << "(6) - PS3's ($650)        = " << ps_int << endl;
     cout << "(7) - Wii's ($250)        = " << wii_int << endl;
     cout << "(8) - Dreamcast's ($150)  = " << dc_int << endl;


}

int purchase_function(int shop)
{
     if (shop == 1) { cout << "Beer\n"; }
     if (shop == 2) { cout << "Cake\n"; }
     if (shop == 3) { cout << "Bannana\n"; }
     if (shop == 4) { cout << "Apples\n"; }
     if (shop == 5) { cout << "Xbox 360\n"; }
     if (shop == 6) { cout << "PS3\n"; }
     if (shop == 7) { cout << "Wii\n"; }
     if (shop == 8) { cout << "Dreamcast\n"; }
     if (shop == 10) { checkout(); }
     what_you_have_bought(shop);
}

int main()
{
    system("color 1a");
    while ( exitprog == false ) {
    int shop = 0;
    what_you_have_bought(shop);
    cout << "\nChoose items to put in trolly or type 10 to go to checkout\n";
    cin >> shop;
    purchase_function(shop);
   
    }
}



.......Yes, you don't need to point it out, I spelt banana wrong... lol
ShadowTH
 
Posts: 6
Joined: Tue Aug 18, 2009 7:39 am

Re: Shopping prog

Postby glinka57 on Thu Oct 08, 2009 9:30 am

3 Errors , at line 33,56 and 70.

cpp(33) : error C4716: 'checkout' : must return a value
cpp(56) : error C4716: 'what_you_have_bought' : must return a value
cpp(70) : error C4716: 'purchase_function' : must return a value

How could you post it without runing a final compile LOLOL.
patch it.
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm

Re: Shopping prog

Postby cyberspy on Fri Oct 09, 2009 12:22 pm

LOL, errors ~ Your functions donot return a value!!!!!
cyberspy
 
Posts: 12
Joined: Sun Sep 13, 2009 4:14 am

Re: Shopping prog

Postby ShadowTH on Sun Oct 11, 2009 5:34 am

Dev C++ Runs it fine.
So I did do a compile before i posted it. >.>
I'm not returning nothin' if I don't have to!
Edit: Fine then ill return 0. I'm not sure if this is even correct but it still works for me.

Code: Select all
    #include <iostream>
    using namespace std;

    //Checkout thing by Aaron McNuggets

    bool exitprog = false;
    int beer_int = 0;
    int cake_int = 0;
    int bannana_int = 0;
    int apple_int = 0;
    int xbox_int = 0;
    int ps_int = 0;
    int wii_int = 0;
    int dc_int = 0;
    int price = 0;

    int checkout()
    {
        while ( beer_int > 0 ) {  price+=3; beer_int--; }
        while ( cake_int > 0 ) {  price+=5; cake_int--; }
        while ( bannana_int > 0 ) {  price+=1; bannana_int--; }
        while ( apple_int > 0 ) {  price+=1; apple_int--; }
        while ( xbox_int > 0 ) {  price+=400; xbox_int--; }
        while ( ps_int > 0 ) {  price+=650; ps_int--; }
        while ( wii_int > 0 ) {  price+=250; wii_int--; }
        while ( dc_int > 0 ) {  price+=150; dc_int--; }
        system("cls");
        cout << "Total price: $" << price << endl;
        cout << "Thank you come again!" << endl;
        cout << "Press enter to restart :)";
        price = 0;
        cin.get();
        cin.get();
        return 0;
    }

    int what_you_have_bought(int shop)
    {
         if (shop == 1) { beer_int++; }
         if (shop == 2) { cake_int++; }
         if (shop == 3) { bannana_int++; }
         if (shop == 4) { apple_int++; }
         if (shop == 5) { xbox_int++; }
         if (shop == 6) { ps_int++; }
         if (shop == 7) { wii_int++; }
         if (shop == 8) { dc_int++; }
         system("cls");
         cout << "(1) - Beer's ($3)         = " << beer_int << endl;
         cout << "(2) - Cake's ($5)         = " << cake_int << endl;
         cout << "(3) - Bannana's ($1)      = " << bannana_int << endl;
         cout << "(4) - Apples's ($1)       = " << apple_int << endl;
         cout << "(5) - Xbox 360's ($400)   = " << xbox_int << endl;
         cout << "(6) - PS3's ($650)        = " << ps_int << endl;
         cout << "(7) - Wii's ($250)        = " << wii_int << endl;
         cout << "(8) - Dreamcast's ($150)  = " << dc_int << endl;
         return 0;

    }

    int purchase_function(int shop)
    {
         if (shop == 1) { cout << "Beer\n"; }
         if (shop == 2) { cout << "Cake\n"; }
         if (shop == 3) { cout << "Bannana\n"; }
         if (shop == 4) { cout << "Apples\n"; }
         if (shop == 5) { cout << "Xbox 360\n"; }
         if (shop == 6) { cout << "PS3\n"; }
         if (shop == 7) { cout << "Wii\n"; }
         if (shop == 8) { cout << "Dreamcast\n"; }
         if (shop == 10) { checkout(); }
         what_you_have_bought(shop);
         return 0;
    }

    int main()
    {
        system("color 1a");
        while ( exitprog == false ) {
        int shop = 0;
        what_you_have_bought(shop);
        cout << "\nChoose items to put in trolly or type 10 to go to checkout\n";
        cin >> shop;
        purchase_function(shop);
       
        }
    }


There is is. The almighty version 1.1. Have fun!
ShadowTH
 
Posts: 6
Joined: Tue Aug 18, 2009 7:39 am

Re: Shopping prog

Postby C++ on Sun Oct 11, 2009 5:46 am

ShadowTH wrote:Dev C++ Runs it fine.
So I did do a compile before i posted it. >.>
I'm not returning nothin' if I don't have to!
Edit: Fine then ill return 0. I'm not sure if this is even correct but it still works for me.

Code: Select all
    #include <iostream>
    using namespace std;

    //Checkout thing by Aaron McNuggets

    bool exitprog = false;
    int beer_int = 0;
    int cake_int = 0;
    int bannana_int = 0;
    int apple_int = 0;
    int xbox_int = 0;
    int ps_int = 0;
    int wii_int = 0;
    int dc_int = 0;
    int price = 0;

    int checkout()
    {
        while ( beer_int > 0 ) {  price+=3; beer_int--; }
        while ( cake_int > 0 ) {  price+=5; cake_int--; }
        while ( bannana_int > 0 ) {  price+=1; bannana_int--; }
        while ( apple_int > 0 ) {  price+=1; apple_int--; }
        while ( xbox_int > 0 ) {  price+=400; xbox_int--; }
        while ( ps_int > 0 ) {  price+=650; ps_int--; }
        while ( wii_int > 0 ) {  price+=250; wii_int--; }
        while ( dc_int > 0 ) {  price+=150; dc_int--; }
        system("cls");
        cout << "Total price: $" << price << endl;
        cout << "Thank you come again!" << endl;
        cout << "Press enter to restart :)";
        price = 0;
        cin.get();
        cin.get();
        return 0;
    }

    int what_you_have_bought(int shop)
    {
         if (shop == 1) { beer_int++; }
         if (shop == 2) { cake_int++; }
         if (shop == 3) { bannana_int++; }
         if (shop == 4) { apple_int++; }
         if (shop == 5) { xbox_int++; }
         if (shop == 6) { ps_int++; }
         if (shop == 7) { wii_int++; }
         if (shop == 8) { dc_int++; }
         system("cls");
         cout << "(1) - Beer's ($3)         = " << beer_int << endl;
         cout << "(2) - Cake's ($5)         = " << cake_int << endl;
         cout << "(3) - Bannana's ($1)      = " << bannana_int << endl;
         cout << "(4) - Apples's ($1)       = " << apple_int << endl;
         cout << "(5) - Xbox 360's ($400)   = " << xbox_int << endl;
         cout << "(6) - PS3's ($650)        = " << ps_int << endl;
         cout << "(7) - Wii's ($250)        = " << wii_int << endl;
         cout << "(8) - Dreamcast's ($150)  = " << dc_int << endl;
         return 0;

    }

    int purchase_function(int shop)
    {
         if (shop == 1) { cout << "Beer\n"; }
         if (shop == 2) { cout << "Cake\n"; }
         if (shop == 3) { cout << "Bannana\n"; }
         if (shop == 4) { cout << "Apples\n"; }
         if (shop == 5) { cout << "Xbox 360\n"; }
         if (shop == 6) { cout << "PS3\n"; }
         if (shop == 7) { cout << "Wii\n"; }
         if (shop == 8) { cout << "Dreamcast\n"; }
         if (shop == 10) { checkout(); }
         what_you_have_bought(shop);
         return 0;
    }

    int main()
    {
        system("color 1a");
        while ( exitprog == false ) {
        int shop = 0;
        what_you_have_bought(shop);
        cout << "\nChoose items to put in trolly or type 10 to go to checkout\n";
        cin >> shop;
        purchase_function(shop);
       
        }
    }


There is is. The almighty version 1.1. Have fun!


Your compiler is not adhering to standard C++
Any half decent compiler will complain when you don't return a value from a function that should return a value.
Look for a compiler option that turns on C++ standard code compliance.
You will suddenly see your compiler warning or giving errors where at first it compiled fine.
This shows how important it is to not shut up a compiler or make it compile code that shouldn't compile without warnings/errors.
New to C++ programming? Click here
C++
teh awesome
 
Posts: 217
Joined: Sun May 25, 2008 7:45 am

Re: Shopping prog

Postby ShadowTH on Sat Oct 17, 2009 11:31 pm

Yes well i had no idea. I'll download Microsoft Visual C++ then. Anyway, lets back off from the discussing of my compiler not complaining about missing return values... Does anyone here use Allegro? :P
ShadowTH
 
Posts: 6
Joined: Tue Aug 18, 2009 7:39 am


Return to Full programs

Who is online

Users browsing this forum: No registered users and 0 guests