|
Home > Archive > Linux/Unix > November 2003 > c++ errors
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I asked for help with this a few days ago, and thanks to the feedback was able to get the program complied. I have a new problem now, in that the program isnt waiting for inputs before continuing to the next line of the program.
(sorry i have a feeling this will be something really simple that i have over looked, this is my first program)
1. // This program calculates varables in ohms law
2. // Author: Ian Stewart Date: 30/10/03
3. // Metrowerks CodeWarrior version
4.
5.
6. #include <iostream>
7. using namespace std;
8.
9. int main()
10. {
11. int choice;
12. char I;
13. char V;
14. char R;
15. int Q;
16. int flag = 1;
17. while (flag = 1)
18. {
19. cout << "What do you wan to calculate, V I or R? "; // ask which variable is to be calculated
20. cin >> choice;
21.
22. if(choice==V) // calculate voltage
23. {
24. {
25. cout << "please enter I? "; // ask for I
26. }
27. cin >> I;
28. cout << "please enter R? "; // ask for R
29. cin >> R;
30. int q = I * R; // multiply I and R then print
31. cout << "V is (" << q <<")" << endl;
32. }
33. if (choice==R); // Calculate resistance
34. {
35. {
36. cout << "please enter V? "; // ask for value of V
37. }
38. cin >> V;
39. cout << "please enter I "; // ask for I
40. cin >> I;
41. int p = V/I; // devide V by I and print
42. cout << "R is (" << p <<")" << endl;
43. }
44. if (choice==I); // Calculate current
45. {
46. {
47. cout << "please enter V? "; // ask for value of V
48. }
49. cin >> V;
50. cout << "please enter R "; // ask for R
51. cin >> R;
52. int O = V/R; // devide V by R and print
53. cout << "I is (" << O <<")" << endl;
54. }
55. if (choice==Q);
56. {
57. flag = 0;
58. }
59. }
60. return 0;
61. }
any help would be greatly appresiated.
ian | |
|
| dude, start from beginning,
and then write a section at a time, then complile test. when encounter error, look at the line number and try to debug.
for example
how do you =="v" in one moment and then use ==R the next?
and since when do you add ; to if else?
and what is
if
else if
else if
else
else if
???
and then what happen to Q ?
and when you copy/paste, include everything, inlcuding the last }
and edit your post to make it easy for others to read it, I stop looking at in in 2 seconds.
some decent site for you to learn some basic
http://www.cprogramming.com/
http://www.cplusplus.com/doc/tutorial/
http://www.functionx.com/cpp/ | |
| Papiya 2003-11-03, 7:56 am |
| Can you add line numbers and use the code flag so that this output is a bit more readbale? | |
| mindmesh 2003-11-03, 5:10 pm |
| I'm just learning this myself but:
else (choice==I); // Calculate current
This should be:
else if(choice==I); // Calculate current
I counted out the lines and that appears to be line 43. I'm assuming 54 is the else if statement after the else you have in there.
Also, if that doesn't work. upload the code into a word or text doc /w the #'s this way it is laid out correctly. Just an fyi. |
|
|
|
|