Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,072 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,785 people online right now. Registration is fast and FREE... Join Now!




help me with this simple program

 
Reply to this topicStart new topic

help me with this simple program, urgent

EquinoX
1 Feb, 2008 - 02:17 PM
Post #1

D.I.C Head
**

Joined: 19 Jan, 2007
Posts: 63


My Contributions
I have a program called donut.c and the code is like this:


CODE

#include <stdio.h>

int main()
{
    double dozen_donut_cost;
    int donuts_eaten;
    int i = 0;
    double donuts_cost;

    return 0;
}


then when I want to execute donut, the instruction is:
./donut < t0

where the file t0 contains:
3.00 12 .5 .5 .5 .5 .5 .75 .75 .75 .75 1.0 1.0 1.0

how do I assign the variable dozen_donut_cost so that it equals 3.00? Which is the first value in file?? Thanks
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Help Me With This Simple Program
1 Feb, 2008 - 02:37 PM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi, check this tutorial:

http://www.cprogramming.com/tutorial/cfileio.html
User is offlineProfile CardPM
+Quote Post

EquinoX
RE: Help Me With This Simple Program
1 Feb, 2008 - 02:39 PM
Post #3

D.I.C Head
**

Joined: 19 Jan, 2007
Posts: 63


My Contributions
QUOTE(PennyBoki @ 1 Feb, 2008 - 03:37 PM) *


hey I checked your tutorial and I still don't get it how do I assign it to a variable
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Help Me With This Simple Program
1 Feb, 2008 - 03:14 PM
Post #4

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
OK. is the file like this:
1
2
3
4


or

1 2 3 4

?And Here is what you do: read from the file using some sort of loop. The condition is reaching the end of the file. Use the functions like fgets OR fgetc, then cast from char* to double.
User is offlineProfile CardPM
+Quote Post

EquinoX
RE: Help Me With This Simple Program
1 Feb, 2008 - 03:18 PM
Post #5

D.I.C Head
**

Joined: 19 Jan, 2007
Posts: 63


My Contributions
QUOTE(PennyBoki @ 1 Feb, 2008 - 04:14 PM) *

OK. is the file like this:
1
2
3
4


or

1 2 3 4

?And Here is what you do: read from the file using some sort of loop. The condition is reaching the end of the file. Use the functions like fgets OR fgetc, then cast from char* to double.


the file is like 1 2 3 4 and does main has to take an arguments? what will the main arguments be like?
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Help Me With This Simple Program
1 Feb, 2008 - 03:50 PM
Post #6

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
An example that should get you started:

http://www.cprogramming.com/tutorial/c/lesson14.html


User is offlineProfile CardPM
+Quote Post

musya
RE: Help Me With This Simple Program
1 Feb, 2008 - 03:53 PM
Post #7

D.I.C Regular
Group Icon

Joined: 25 Apr, 2007
Posts: 296



Thanked: 1 times
Dream Kudos: 50
My Contributions
probably pass in a char array (char[]) into main, and then loop through that and select the first number or the numbers that are before the first ' ' (space) and then assign them to dozen_donut_cost.
User is offlineProfile CardPM
+Quote Post

EquinoX
RE: Help Me With This Simple Program
1 Feb, 2008 - 04:27 PM
Post #8

D.I.C Head
**

Joined: 19 Jan, 2007
Posts: 63


My Contributions
QUOTE(musya @ 1 Feb, 2008 - 04:53 PM) *

probably pass in a char array (char[]) into main, and then loop through that and select the first number or the numbers that are before the first ' ' (space) and then assign them to dozen_donut_cost.


say that I want to leave main as int main(), but when I execute the program I would like it to be able to do ./donut 3.0
and I want to get the value of 3.0
User is offlineProfile CardPM
+Quote Post

musya
RE: Help Me With This Simple Program
1 Feb, 2008 - 10:36 PM
Post #9

D.I.C Regular
Group Icon

Joined: 25 Apr, 2007
Posts: 296



Thanked: 1 times
Dream Kudos: 50
My Contributions
As far as I know you need main to take in an argument in order for that to work that way, but if I'm wrong somebody correct me please.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 11:06PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month