When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
54 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.
State your problem clearly and provide all necessary details:
Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:
```cpp
int main() {}
```
int main() {}
I keep getting this when trying to format the code :/
Your message could not be delivered. This is usually because you don't share a server with the recipient or the recipient is only accepting direct messages from friends. You can see the full list of reasons here:
Nah it's still doing it. I went into my setting to change things and everything 😦
how long is your code?
With comments included 77 lines
Not sure why it's not letting you post it then. Just try to post it without formatting it
//A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm
//ships cartons of milk to a local grocery store. The cost of producing
//one liter of milk is $0.38, and the profit of each carton of milk is
//$0.27. Write a program that does the following:
//a. Prompts the user to enter the total amount of milk produced in the
//morning.
//b. Outputs the number of milk cartons needed to hold milk. (Round
//your answer to the nearest integer.)
//c. Outputs the cost of producing milk.
//d. Outputs the profit for producing milk.
//Include header file to allow input/output
#include <iostream>
//Include directive to avoid unnecessary repetition.
using namespace std;
//Declare a constant to represent the capacity of a carton of milk.
const double carton = 3.78;
//Create main function.
int main();
{
//Declare variables to represent milk, milk cartons, cost
//to produce, profits, cost per milk produced, and profit
//per milk produced.
double milk;
int milk_Carton;
double cost = 0.38;
double profit = 0.27;
double cost_Per, profit_Per;
//Prompts the user to enter the total amount of
//milk produced in the morning.
cout << "Enter, in liters, the total quantity of milk produced: " << endl;
//Assign the user's input to the milk variable.
cin >> milk;
//Assign value to previously declared variable milk_carton.
milk_Carton = milk / carton;
//Outputs the number of milk cartons needed to
//hold milk. (Round your answer to the
//nearest integer.)
cout << "The number of milk cartons needed to hold milk: " << milk_Carton << endl;
//Assign values to previously declared variables cost_Per
//and profit_Per.
cost_Per = milk * cost;
profit_Per = milk_Carton * profit;
I think it's because I don
dont have nitro. This isn't the full code by the way
Let me delete the comments real quick and see if itll allow me to then
//A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm
//ships cartons of milk to a local grocery store. The cost of producing
//one liter of milk is $0.38, and the profit of each carton of milk is
//$0.27. Write a program that does the following:
//a. Prompts the user to enter the total amount of milk produced in the
//morning.
//b. Outputs the number of milk cartons needed to hold milk. (Round
//your answer to the nearest integer.)
//c. Outputs the cost of producing milk.
//d. Outputs the profit for producing milk.
//Include header file to allow input/output
#include <iostream>
//Include directive to avoid unnecessary repetition.
using namespace std;
//Declare a constant to represent the capacity of a carton of milk.
const double carton = 3.78;
//Create main function.
int main();
{
double milk;
int milk_Carton;
double cost = 0.38;
double profit = 0.27;
double cost_Per, profit_Per;
cout << "Enter, in liters, the total quantity of milk produced: " << endl;
cin >> milk;
milk_Carton = milk / carton;
cout << "The number of milk cartons needed to hold milk: " << milk_Carton << endl;
cost_Per = milk * cost;
profit_Per = milk_Carton * profit;
cout << "The cost of producing milk: " << cost_Per << endl;
cout << "Profit: " << profit_Per << endl;
return 0;
}
There we go!
What are the errors?
it's saying my identifiers are undefined
and an expected declaration in line 28
^this is the first error
You can either copy paste the errors or screenshot them
It would be tedious to describe all 18 errors lol
Can you see what's wrong with this part of the code?
int main();
{
is the semi colon unnecessary?
yes
It's like you're doing forward declaration if you use semicolon after a function
Gotcha. So no function uses the semi colon at the end?
If you're forward declaring a function because the function is below the main function you would use it and some other specific cases but other than that, no.
Oh it ran!
Oh so you forward functions that are within the main function?
This is like my 3rd week into c++
Super intimidating so far
for example
int add(int a, int b);
int main(){
int a = 5;
int b = 6;
std::cout << add (a, b);
}
int add(int a, int b){
return a + b;
}
Wow, this code is pretty good for your 3rd week
It took me forever 😅
It's already being practical
Using the right type of resources as a beginner is pretty helpful, I'll leave you with some below that are recommended
We generally recommend a good book to learn the necessary fundamentals:
To actually write and run C++ code, you will need a compiler, editor, and debugger. We strongly recommend to start out using an IDE, which will provide all these tools for you:
The wise programmer is told about the debugger and uses it.
The average programmer is told about the debugger and avoids it.
The foolish programmer is told about the debugger and laughs at it.
I'm learning from the D.S. Malik C++ Programming textbook right now. This thing is like a phonebook lol
learncpp is free from the three of them and a lot of people recommend it
I really appreciate all of your help and advice!
You welcome!
Take care!