<< Previous Page 2 of 2
Bayou is entirely correct; thanks for clarifying that. However, my spin on it is that I prefer to not care what order my functions are defined in (as is the behaviour in my favourite language: C#). Writing an .h file, while irritatingly tedious, allows you to ignore the order that functions are defined in. But at the end of the day (unless you're sharing code) it's up to you as to how you want to handle it.bayou wrote:
I'm probably just confusing the situation, but what the hell. Note you don't have to forward-declare functions in a header file, or in fact at all. Like Ratfink said, the compiler reads through the file from top to bottom, and you can't have a call to a function it doesn't know about yet. You can define/declare the function in one go so long as it appears before your call to it.
// Practice problems from Tony Gaddis BookThe code in red is the line of code I'm having issues with. The error it gives me is that is there are too many characters in the constant. All I'm trying to do is assignt 'Claw Hammers' to the first element of the array product. Help please?
// Involves problems 11.4 - 11.8
#include "stdafx.h"
#include <iostream>
using namespace std;
struct Product
{
char description[50]; //Product description
int partNum; //Part Number
double cost; //Product cost
};
int _tmain(int argc, _TCHAR* argv[])
{
///Part 11.4 of the series
Product product1[100];
//Part 11.5 of the series
for(int f = 0; f < 100; f++)
{
product1[f].description[f] = ' ';
product1[f].cost=0;
product1[f].partNum=0;
}
//Part 11.6 of the series
product1[0].description = 'Claw Hammer';
product1[0].partNum = 547;
product1[0].cost = 8.29;
//Part 11.7 of the series
for(int j = 0; j < 100; j++)
{
cout << "Item: #" << (j+1);
cout << "\n Name:" << product1[j].description;
cout << "\n Cost: $" << product1[j].cost;
cout << "\n Part Number: #" << product1[j].partNum;
}
return 0;
}
I did that. Now the error it is giving me is the following:bayou wrote:
I believe the problem is you're using single quotes, where you need to use double quotes. A literal in single quotes is a single character, whereas a literal in double quotes is a string of characters.
product1[f].description = "";Now the error it is giving me is: that the expression must be a modifiable lvalue.
<< Previous Page 2 of 2