| | |
C++ Homework Assistance...
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
I am new to C++ and programming in general, and am working on an upcoming homework assignment. I have run into several problems and would greatly appreciate assistance. The assignment is to write a code to determine area and volume in C++, using a While Loop. I am stuck with the while statement, I am not sure how to state when I want it to stop. Below is what I have so far.
Thank you,
bmgee13
c Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int area (int l, int w); // function prototype int volume (int l, int w, int d); // function prototype int main (int argc, char* argv[]) { int length, width, depth; // parameters for the areas and volumes int result; //result is output cout << endl; // read in the values of length, width, and depth While (?) { cout << "If you want the result of the calculation to be an area,"; cout << endl; cout << "place a 0 in the depth parameter "; cout << endl << endl; cout << "Enter a length (postive integer): "; cin >> length; cout << "Enter a width (postive integer): "; cin >> width; cout << "Enter a depth (postive integer): "; cin >> depth; cout << endl; if (depth == 0) { result = area (length, width); cout << "With a length of " << length; cout << " and a width of " << width; cout << " the area is " << result << endl; } else { result = volume (length, width, depth); cout << "With a length of " << length; cout << " a width of " << width; cout << " and a depth of " << depth; cout << " the volume is " << result << endl; } // end if } // end loop return 0; } // end main function int area (int l, int w) { int result; result=area(l,w); return result; } // end area function int volume (int l, int w, int d) { int result; result=volume(l,w,d); return result; } // end volume function
bmgee13
Last edited by WaltP; Apr 22nd, 2007 at 11:11 pm. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
>I am stuck with the while statement, I am not sure how to state when I want it to stop.
Usually you tell the user to enter a negative number to quit when dealing with numbers (assuming of course, that you don't need negative numbers from the input). So the condition would be something like
The only problem is that you usually ask the user to enter a negative number at the first input statement at the prompt. So then you must ask the user for the dimensions of the box before the program will exit.
You can always
>Isnt it meant to be like: While(car = red)
That would be wrong, because
Usually you tell the user to enter a negative number to quit when dealing with numbers (assuming of course, that you don't need negative numbers from the input). So the condition would be something like
C++ Syntax (Toggle Plain Text)
while (input >= 0)
The only problem is that you usually ask the user to enter a negative number at the first input statement at the prompt. So then you must ask the user for the dimensions of the box before the program will exit.
You can always
break out of the loop if you find that the number is negative, which is probably the easiest for you (for now).>Isnt it meant to be like: While(car = red)
That would be wrong, because
= is an assignment operator. You'd be assigning car to red, which would be rather pointless, and quite likely you'd enter an infinite loop (if red never changed). "Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
Thank you for your assistance, I do appreciate it. Although I am still unclear on the while statement, I have now used
While(result !=0). However, I am now receiving the error message
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup I tried to look up this error message in the MS Help section, but am not receiving as much information as I would have hoped for.
While(result !=0). However, I am now receiving the error message
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup I tried to look up this error message in the MS Help section, but am not receiving as much information as I would have hoped for.
It's got something to do with Microsoft wanting t_main with their compiler, although I don't really know much about it.
I'd research it a little bit more, except I want to watch the hockey game. Sorry
I'd research it a little bit more, except I want to watch the hockey game. Sorry
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
•
•
Thank you for your assistance, I do appreciate it. Although I am still unclear on the while statement, I have now used
While(result !=0). However, I am now receiving the error message
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup I tried to look up this error message in the MS Help section, but am not receiving as much information as I would have hoped for.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- C++ A little homework help, Thanks very much for the last assistance (C++)
- Homework assistance (C++)
Other Threads in the C++ Forum
- Previous Thread: first array bit
- Next Thread: hex code
Views: 1754 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






