Web Analytics Made Easy -
StatCounter Complete newbie to programming here, don't be too harsh. - CodingForum


No announcement yet.

Complete newbie to programming here, don't be too harsh.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Complete newbie to programming here, don't be too harsh.

    Hi there, I have been trying for the past hour to figure out what is wrong with this simple program for one of my college courses, but I can't seem to figure it out.

    The code of the program is as follows:

    // Program that tells the user how many desks they can build.
    // Each desk takes 6 boards to make.
    // Displays the amount of profit the individual will make if they sold the desks.

    // Created by Ryan Johnson

    #include <iostream>

    using namespace std;

    int main()
    int boards ;
    int desks ;
    double amountCharge ;
    double totalAmount = amountCharge * desks ;

    cout << "How many boards do you have? " ;
    cin >> boards ;
    cout << endl ;
    cout << "You can make the number of desks listed below."<< endl;
    cout << boards / 6 ;
    cout << endl ;
    cout << "You will have this many boards left over after building the desks ---> " ;
    cout << boards % 6 ;
    cout << endl ;
    cout << endl ;
    cout << "How much would you like to charge for the desk? " ;
    cin >> amountCharge ;
    cout << "If you were to sell all of the desks, you would make the amount of money listed below." ;
    cout << endl;
    cout << totalAmount ;

    I need to display the total cost of the complete desks that can be sold at the end of the code. It is probably some simple mistake, but I need some help.


  • #2
    You are calculating totalAmount in the wrong place - you need to calculate it after the values have been entered - atthe time you are currently running it neither of the values to be multiplied has a value yet.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.