Nov 12, 2015 at 4:35am UTC
I don't know why my program isn't working. When I compile the program the command prompt is literally blank. Not even the "Press any button to continue..." pops up. The assignment is to create a shipping manifest that reads data from a file and determines a shipping fee and keeps track of the total packages, weight, and charges of the packages. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
int weight, code, price, truck;
int t1total = 0, t2total = 0, t3total = 0, t1weight = 0, t2weight = 0, t3weight = 0, t1profit = 0, t2profit = 0, t3profit = 0;
ifstream inData;
inData.open("manifest.txt" );
//Primary read
cin >> weight >> code;
//Loop
while (inData)
{
inData >> weight >> code;
if (weight < 6 && code == 1)
{
price = 10;
truck = 1;
t1total = (t1total + 1);
t1weight = (t1weight + weight);
t1profit = (t1profit + price);
}
if (weight < 6 && code == 2)
{
price = 10;
truck = 2;
t2total = (t2total + 1);
t2weight = (t2weight + weight);
t2profit = (t2profit + price);
}
if (weight < 6 && code == 3)
{
price = 10;
truck = 3;
t3total = (t3total + 1);
t3weight = (t3weight + weight);
t3profit = (t3profit + price);
}
if (weight < 11 && code == 1)
{
price = 15;
truck = 1;
t1total = (t1total + 1);
t1weight = (t1weight + weight);
t1profit = (t1profit + price);
}
if (weight < 11 && code == 2)
{
price = 25;
truck = 2;
t2total = (t2total + 1);
t2weight = (t2weight + weight);
t2profit = (t2profit + price);
}
if (weight < 11 && code == 3)
{
price = 35;
truck = 3;
t3total = (t3total + 1);
t3weight = (t3weight + weight);
t3profit = (t3profit + price);
}
}
inData >> weight >> code;
cout << "The total number of packages on Truck 1 is " << t1total << "." << "Amassing a total weight of " << t1weight << "." << "Making a total profit of " << t1profit << "." << endl;
cout << "The total number of packages on Truck 2 is " << t2total << "." << "Amassing a total weight of " << t2weight << "." << "Making a total profit of " << t2profit << "." << endl;
cout << "The total number of packages on Truck 3 is " << t3total << "." << "Amassing a total weight of " << t3weight << "." << "Making a total profit of " << t3profit << "." << endl;
return 0;
}
Last edited on Nov 12, 2015 at 4:35am UTC
Nov 12, 2015 at 5:33am UTC
Man do I feel dumb. That was the most simple solution ever. Thanks xD
Nov 12, 2015 at 8:04am UTC
A general good tip is that you should always, ALWAYS prompt for input. There are situations where you'll just want to keep entering data after the first prompt, but again, there's still a prompt. It doesn't even have to be a long, drawn-out question, it could literally be like:
std::cout << "Weight? : " ;
Cout statements in certain places also help with debugging code once you get deep enough.
Nov 13, 2015 at 1:50am UTC
It's for my C++ class in college.
Nov 13, 2015 at 1:53am UTC
i meant if you input a few numbers, what should the output be? *If it works correctly*