Post: My First Application (started C++ today)
02-26-2011, 05:45 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Hello guys, can you please give me some feedback on my app? It's a simple command prompt based thing that will calculate how much more money you need to buy something. Here it is:

    #include "stdafx.h"

#include <iostream>


int subtract(int x, int y)
{
return x - y;
}


int main()
{
using namespace std;
cout << "How much money does the desired item cost?";
int x;
cin >> x;
cout << "How much money do you have currently?";
int y;
cin >> y;
cout << "You need this much more: " << subtract(x, y) << endl;
return 0;
}


Note: This was done in Visual C++ 2010 Express.

How could I improve it? How could I code it to ask how many items are wanted, and make it calculate how much more is needed to purchase the 2-3 items.

Thanks!
02-26-2011, 08:40 PM #2
Ritztro
I am a Game Developer
Originally posted by Leo99756 View Post
Hello guys, can you please give me some feedback on my app? It's a simple command prompt based thing that will calculate how much more money you need to buy something. Here it is:

    #include "stdafx.h"

#include <iostream>


int subtract(int x, int y)
{
return x - y;
}


int main()
{
using namespace std;
cout << "How much money does the desired item cost?";
int x;
cin >> x;
cout << "How much money do you have currently?";
int y;
cin >> y;
cout << "You need this much more: " << subtract(x, y) << endl;
return 0;
}


Note: This was done in Visual C++ 2010 Express.

How could I improve it? How could I code it to ask how many items are wanted, and make it calculate how much more is needed to purchase the 2-3 items.

Thanks!


Well the function really isnt needed even though it is cool. Also try developing for linux now and use vim. I know that really advanced programmers use it and I am just starting to use it so start early. Get ubuntu in virtual box and then g++ and gcc and use vim. THere are tuts out there. It might seem bad at first but once you get used to it it is really fast.
02-26-2011, 09:37 PM #3
Originally posted by Dutch View Post
Well the function really isnt needed even though it is cool. Also try developing for linux now and use vim. I know that really advanced programmers use it and I am just starting to use it so start early. Get ubuntu in virtual box and then g++ and gcc and use vim. THere are tuts out there. It might seem bad at first but once you get used to it it is really fast.


Thanks for the advice.
02-26-2011, 09:43 PM #4
Originally posted by Leo99756 View Post
Hello guys, can you please give me some feedback on my app? It's a simple command prompt based thing that will calculate how much more money you need to buy something. Here it is:

    #include "stdafx.h"

#include <iostream>


int subtract(int x, int y)
{
return x - y;
}


int main()
{
using namespace std;
cout << "How much money does the desired item cost?";
int x;
cin >> x;
cout << "How much money do you have currently?";
int y;
cin >> y;
cout << "You need this much more: " << subtract(x, y) << endl;
return 0;
}


Note: This was done in Visual C++ 2010 Express.

How could I improve it? How could I code it to ask how many items are wanted, and make it calculate how much more is needed to purchase the 2-3 items.

Thanks!


    #include <iostream>

using namespace std;

int subtract(int x, int y)
{
return x - y;
}

int main()
{
int quantity = 0;
int price = 0;
int money = 0;

int tempNum;

cout<<"How many items do you have? ";
cin>>quantity;

for(short count = 1; count <= quantity; count++)
{
cout << "How much money does item["<<count<<"] cost?";
cin >> tempNum;
price += tempNum;
}

cout << "How much money do you have currently?";
cin >> money;

cout << "You need this much more: " << subtract(money, price) << endl;
return 0;
}

The following 2 users say thank you to TheUberFail for this useful post:

<Jimbo>, Leo99756
02-26-2011, 09:44 PM #5
Girby2K11
☮ ☯ ☢ ✔ ➝
what was the other function for? but anyway if you started c++ yesterday i guess thats fine Smile
03-01-2011, 08:42 PM #6
kiwimoosical
Bounty hunter
    #include <iostream>
using namespace std;
void main(void)
{
system("cls");
double numbers[2];
char quit[1];
cout << "How much money does the desired item cost?" << endl;
cin >> numbers[0];
cout << "How much money do you have currently?";
cin >> numbers[1];
cout << "You need " <<(numbers[0] - numbers[1] > 0) ? (numbers[0] - numbers[1] + " more dollars.") : (" no more money to buy your item, you have enough!") << "\nWould you like to continue? (y/n):<< endl;
cin.getline(quit, 1);
quit[0] == 'n' ? system("exit") : main();
}

Lulz. New coders following online tuts, all those little guys teach is syntax, real skill comes from experience, just saying Smile
03-01-2011, 08:59 PM #7
x-MaGiiKZz-o
Who’s Jim Erased?
Okay, I just started C++ and can hardly do anything, however that is impressive. I understand a lot of them codes and its good, nice job!
03-11-2011, 07:11 PM #8
    
#include "stdafx.h"
#include <iostream>

int main()
{
using namespace std;
cout << "How much money does the desired item cost?";
int x;
cin >> x;
cout << "How much money do you have currently?";
int y;
cin >> y;

if (x > y)
{
cout << "You do not have enough money to buy this item?";
}

else

cout << "You need this much more: " << y - x << endl;
return 0;
}
Last edited by MoBaTeY ; 03-11-2011 at 07:13 PM.
03-12-2011, 03:00 AM #9
kiwimoosical
Bounty hunter
Originally posted by MoBaTeY View Post
    
#include "stdafx.h"
#include <iostream>

int main()
{
using namespace std;
cout << "How much money does the desired item cost?";
int x;
cin >> x;
cout << "How much money do you have currently?";
int y;
cin >> y;

if (x > y)
{
cout << "You do not have enough money to buy this item?";
}

else

cout << "You need this much more: " << y - x << endl;
return 0;
}


Mine is like yours but shorter, faster, and better Happy
03-12-2011, 12:10 PM #10
Originally posted by kiwimoosical View Post
Mine is like yours but shorter, faster, and better Happy


Explicit variable names do not speed up the application btw Happy!!! xD

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo