prodstar 0 Light Poster
for(int ROWS = 0; ROWS < 6; ROWS++)
{
        for(int COLUMNS = 0; COLUMNS < 4; COLUMNS++)
       {
            inputFile >> ShippingData[ROWS][COLUMNS];
            cout << ShippingData[ROWS][COLUMNS]<<" ";
          //this loop is going for each column in a particular row
         //after each element there is a space
        }
    //we are here after a row has been completed (after we've gone 
    //through all the columns
   cout <<endl;  //or cout <<"\n";
    //so at the end of the row we place a newline character  

}

hey thanks your help, really apprectice it!!!

one last problem, when the table opens up, its missing the last 2 numbers on the first and second rows 5 & 6.50
dont know why tho =/

prodstar 0 Light Poster

If you want it in a table put a newline after the inner loop but before the close of the outer loop. It just happens to display that way, it's all in the array in rows/columns.

i have no idea what your saying =/

sorry what new line?

prodstar 0 Light Poster

Yes.

i editted my post sorry

yeah i managed to output all the data

the thing is its not in a table, more like in a straight line

prodstar 0 Light Poster

You are trying to output shippingData on line 87 which will give you the array pointer when you output it. You need to output shippingData[ROWS][COLUMNS] . Output a space after each one so you can see the values separated out (and if you want put a newline outside of the inner loop at the bottom to have it put the row on a new line).

Step back and take it slow. If you're rushing through it you're not thinking it through...

actually ive done it, its outputted the data

the thing is its not in a table

prodstar 0 Light Poster

ShippingData

alright i changed int ShippingData [6][4]; to float ShippingData [6][4];
compiled it came up with the same 02xfeb08 message

here is my code

// This program will calculate the charges for shipping
#include <iostream>
#include <iomanip>
#include <fstream>


using namespace std;
int main()
{ // curly #1
    char choice; //choices available in the main menu.
    float weight; // Weight to be entered.
    int weightcategory;
    int shippingzone; // Shipping Zone to be selected.
    int customeridno; // Customer ID Number.
    int zone;
    int charge;
    
    
    float ShippingData[6][4];
    int COLUMNS;
    int ROWS;
    ifstream inputFile;
      
    cout << "Welcome to the DOWHILE FREIGHT ordering cart" << endl;
    cout << "-------------MENU--------------" << endl;
    cout << "1. To begin ordering enter '1'"  << endl;
    cout << "2. To quit enter '2'" << endl;
    cout << "-------------------------------" << endl;
    cout << "Choose an option (enter number):" << endl;
    cin >> choice;
    
    if(choice == '1')
    {   // curly #2      
              customeridno = rand() * rand();
              cout << "----------------------------------------" << endl;
              cout << "Your Customer ID number is " << customeridno << endl;
              cout << "----------------------------------------" << endl;
              cout << "Please Enter the weight of your item" << endl; // Enter the weight of your item
              cout << "We ship items between 1 to 60KG" << endl;
              cin >> weight;
              
              do 
              { // curly #3
              if(weight >= 1 && weight <= 60)
              { // curly #4
                        if (weight >= 1 && weight < 10)
                        weightcategory = 0;
                        else if (weight >= 10 && weight < 20)
                        weightcategory = …
prodstar 0 Light Poster

Change your array back to float and it works.

which one is it ? i forgot =//// so stressed

prodstar 0 Light Poster

Does your file have the labels in it or is it just the numbers?

i deleted the while loop on line 85

moved 84 to 91

compiled it and it spammed me with random messages such as " 0x28feb0"

my file only has numbers no labels

prodstar 0 Light Poster

You never took any input from the file.

replace line 4 (in the second snippet) with inputFile >> numbers[ROWS][COLUMNS];

alright ive fixed it, i've changed some things around but yeah

i get to the point and i end up crashing the program

please check what i did wrong =/

here is my whole code

// This program will calculate the charges for shipping
#include <iostream>
#include <iomanip>
#include <fstream>


using namespace std;
int main()
{ // curly #1
    char choice; //choices available in the main menu.
    float weight; // Weight to be entered.
    int weightcategory;
    int shippingzone; // Shipping Zone to be selected.
    int customeridno; // Customer ID Number.
    int zone;
    int charge;
    
    
    int ShippingData[6][4];
    int COLUMNS;
    int ROWS;
    ifstream inputFile;
      
    cout << "Welcome to the DOWHILE FREIGHT ordering cart" << endl;
    cout << "-------------MENU--------------" << endl;
    cout << "1. To begin ordering enter '1'"  << endl;
    cout << "2. To quit enter '2'" << endl;
    cout << "-------------------------------" << endl;
    cout << "Choose an option (enter number):" << endl;
    cin >> choice;
    
    if(choice == '1')
    {   // curly #2      
              customeridno = rand() * rand();
              cout << "----------------------------------------" << endl;
              cout << "Your Customer ID number is " << customeridno << endl;
              cout << "----------------------------------------" << endl;
              cout << "Please Enter the weight of your item" << endl; // Enter the weight of your item
              cout << "We ship items between 1 to 60KG" << endl;
              cin >> weight;
              
              do 
              { // curly #3
              if(weight …
prodstar 0 Light Poster

You never took any input from the file.

replace line 4 (in the second snippet) with inputFile >> numbers[ROWS][COLUMNS];

yeah i replaced it but i dont see my rows and columns from my txt =/

prodstar 0 Light Poster

So this is something you probably want to read in before you get to that stage of the program. Will the file always be in that format?

If so, make a 2D array for it, use a nested for loop and read each element in:

for(i over rows)
     for(j over cols)
           filein >> my2Darray[i][j];

If the file size isn't going to be known at run time we can make some adjustments. Now, when you get a package in that section of your program, use your two data points to determine the correct row and column of your table.

yes i need to make a 2D array but i don't know how to, i need the table from the file to be displayed in my program. I did something like this but it came up with hundreds of random numbers.


this is my code

what I declared

const int ARRAY_SIZE = 24;
    float numbers[6][4];
    int COLUMNS;
    int ROWS;
    ifstream inputFile;

this is my code

inputFile.open("shippingcharges.txt");
                                         for (int ROWS = 0; ROWS < 6; ROWS++)
                                         for (int COLUMNS = 0; COLUMNS < 4; COLUMNS++)
                                             cout << numbers[ROWS][COLUMNS] << endl;
                                             
                                         inputFile.close();
prodstar 0 Light Poster

Oh geez. I glazed right over the period. My apologies OP. When you cited the error I thought you meant the .eof part.

Figure out what you need to read in from the file and when (e.g., if the shipping zone is 5 I need the second row, third column or whatever)

customers can choose whatever shipping zone they want from 1 - 4
depending on there weight

Weight		1	2	3	4
1-10KG		2.5	3.5	4	5
10-20KG		3.5	4	5	6.5
20-30KG		4.5	6.5	7.5	10
30-40KG		10	11	12	13.5
40-50KG		13.5	16	20	27.5
50-60KG		32	34	35	38
prodstar 0 Light Poster

.

prodstar 0 Light Poster

Use your >> statement to drive the loop:

while(weightcategory<7 && charge >>shippingcharges[weightcategory][0]);

(since it's a one line statement put the ; after it, but if there's a body to the while don't put that one in)
That avoids having to use the eof at all, which can cause other problems like reading in the last line twice.
You could even do something like test for the weightcategory before you go into the while and take that part out of the test condition, since weightcategory doesn't change in that loop.

hey man, i seriously dont get this

do you have the code for opening txt files

=/

prodstar 0 Light Poster

hi im trying to read a txt file and could you please check what is wrong with this?

this is my code

// This program will calculate the charges for shipping
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
using std :: ifstream;
using namespace std;
int main()
{ // curly #1
    char choice; //choices available in the main menu.
    float weight; // Weight to be entered.
    int weightcategory;
    int shippingzone; // Shipping Zone to be selected.
    int customeridno; // Customer ID Number.
    int zone;
    int charge;
      
    cout << "Welcome to the DOWHILE FREIGHT ordering cart" << endl;
    cout << "-------------MENU--------------" << endl;
    cout << "1. To begin ordering enter '1'"  << endl;
    cout << "2. To quit enter '2'" << endl;
    cout << "-------------------------------" << endl;
    cout << "Choose an option (enter number):" << endl;
    cin >> choice;
    
    if(choice == '1')
    {   // curly #2      
              customeridno = rand() * rand();
              cout << "----------------------------------------" << endl;
              cout << "Your Customer ID number is " << customeridno << endl;
              cout << "----------------------------------------" << endl;
              cout << "Please Enter the weight of your item" << endl; // Enter the weight of your item
              cout << "We ship items between 1 to 60KG" << endl;
              cin >> weight;
              
              do 
              { // curly #3
              if(weight >= 1 && weight <= 60)
              { // curly #4
                        if (weight >= 1 && weight < 10)
                        weightcategory = 0;
                        else if (weight >= 10 && weight < 20)
                        weightcategory = 1;
                        else if (weight >= …
prodstar 0 Light Poster

problem solved thanks alot !!

prodstar 0 Light Poster

hi i'm currently in need of a quit option

i have something like for example click 2 for quit but i don't know how to make a command for it, could someone please help me

prodstar 0 Light Poster

OMGGG thank you jonsca & Nick Evans GEEEESS!!

sorry i'm a beginner with c++ haha

but thank you!

yeah i got another program man, when i type in >60 it brings up you have selected shipping zone2 but it says please enter weight between 1 to 60kg

i dont know why its coming up with this message


plus i dont know how to make a quit option and for some reason my loop at the main menu is not working, when i type in any number besides 1 or 2 it comes up with the message " please enter 1 or 2 " and it would loop back

heres the code

// This program will calculate the charges for

#include <iostream>
#include <iomanip>

using namespace std;
int main()

{   
    char choice;    // Choices in main menu.
    int weight;  // Weight to be entered.
    int shippingzone;    // Shipping Zone to be selected
    
    // Make a choice in the main menu
    cout << "Welcome to the DOWHILE FREIGHT ordering cart" << endl;
    cout << "To begin ordering enter '1'" << endl;
    cout << "To quit enter '2'" << endl;
    cin >> choice;
    
    if (choice == '1'){
               cout << "Please Enter the weight of your item" << endl; // Enter the weight of your item
               cout << "We ship items between 1 to 60KG" << endl;
               }
               cin >> weight;
               if (weight >= 1 && weight <= 60){
                          cout << "We are able to ship that amount …
prodstar 0 Light Poster

hi i'm currently making a program relating to money and i need my c++ to read one of my excel files which has all the prices etc in it

how do i make it work? =/

prodstar 0 Light Poster

Put the curly braces like Nick Evan was saying. If you don't have the braces only the statement immediately below the if statement is associated with it. Put braces around lines 28 to 30. Now that whole grouping is associated with the top if statement.

OMGGG thank you jonsca & Nick Evans GEEEESS!!

sorry i'm a beginner with c++ haha

but thank you!

prodstar 0 Light Poster

We're working our way up to that.

@OP: No, you can only use the comma for variables that are of the same type.

char choice;
int weight;

thanks mate

but when i still enter a number like 61 it still passes through

prodstar 0 Light Poster

How did you declare it as a char? Change it from being a char to an int.

char choice, int weight;

like that?

its not working =/

prodstar 0 Light Poster

weight should be an integer and not a char. You were comparing the ASCII value of the first character (so if you typed in 70 you'd only get the 7 as a character variable holds exactly one character, and 7 has an ASCII value of 55 which is less than 60).

how do i change it to an integer

prodstar 0 Light Poster

Can't be the full code, where is weight declared? Paste your exact code, don't try to paraphrase.

// This program will calculate the charges for


#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    
    char choice, weight;

    cout << "Welcome to the DOWHILE FREIGHT ordering cart" << endl;
    cout << "To begin ordering enter '1'" << endl;
    cout << "To quit enter '2'" << endl;
    
    cin >> choice;
    
    if (choice == '1')
    {
       cout << "Please Enter the weight of your item" << endl;
       cout << "We ship items between 1 to 60KG" << endl;
       
       cin >> weight;
       
    
       if (weight >= 1 && weight <= 60)
          cout << "We are able to ship that amount of weight" << endl;
          cout << "Please Enter the shipping number zone you would like to use" << endl;
          cout << "We have 4 Shipping zones, 1 being standard shipping, 2 Special standard shipping , 3 Express Shipping, 4 Express Special Shipping" << endl;
    
       if (weight < 1 || weight > 60)
          cout << "Please enter weight between 1 to 60KG" << endl;
       
          
    }
    
    else
        cout << "You must enter 1 or 2" << endl;
        
system ("pause");
return 0;
}
prodstar 0 Light Poster

Try "else if" for the 2nd if condition !!!!

doesnt work, it comes up with some error msg saying before else


and heres the full code

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
cout << "Enter weight between 1 to 60KG" << endl;
       cin >> weight;
 
 
       if (weight >= 1 && weight <= 60)
         cout << "Your weight is accepted" << endl;
       if (weight < 1 || weight > 60)
          cout << "Please enter weight between 1 to 60KG" << endl;
prodstar 0 Light Poster

Hi, i'm trying to creating a program on c++ which relates to weight

this is my problem so far

cout << "Enter weight between 1 to 60KG" << endl;
       cin >> weight;
       
    
       if (weight >= 1 && weight <= 60)
         cout << "Your weight is accepted" << endl;
       if (weight < 1 || weight > 60)
          cout << "Please enter weight between 1 to 60KG" << endl;

when i enter a number greater then 60 it still says weight accepted. i don't know why this is happening when it is suppose to say "please enter weight between 1 to 60kg"