need help with general c++ stuff

ok, i just started like a couple days ago to program. i am teaching myself so far from this site and i need someones help with 2 things.

1. Where can i learn more. Like a link to an online FREE course or online FREE textbook.(it has to be FREE)

2. also so far what i taught my self i am learning to make a conversion program.
i am not done yet, but can someone check how i am doing so far. Here it is thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
    system("CLS");
    float answer;
    float number;
    int from;
    int to;
    char loop='y';
  do 
  {
         cout << "Welcome to Measurment System Converter" << endl; 
         cout << "Convert from the following:" << endl;
         cout << "inches[1] centimeters[2] millimeters[3]" << endl;
         cout << "feet[4] yards[5] kilometers[6] miles[7]" <<endl;
         cout << "Enter the corresponding number: "; 
         cin >> from;
         
         switch(from) {
                   case 1:
                        cout << "Convert to the following:" << endl;
                        cout << "centimeters[1] millimeters[2]" << endl;
                        cout << "feet[3] yards[4] kilometers[5] miles[6]" <<endl;
                        cout << "Enter the corresponding number: ";
                        cin >> to;
						switch(to) {
								case 1 :
									cout << "Type in an amount of inches to convert: ";
									cin >> number;
									answer = number * 2.54;
									cout << endl; << number << " converted to centimeters equals: " << answer;
									cout << endl << "Would you like to try again? [y/n]: "
									cin >> loop;
									
								case 2 :
								
									
                        
                   break;
                     
                   case 2:
                        
                   break;
                                           
                   case 3:
                        
                   break; 
                   
                   case 4:
                        
                   break;
                     
                   case 5:
                        
                   break;
                                           
                   case 6:
                   
                   break;
                   
                   case 7:
                        
                   break;
                        
                   default :
                           
                   break;
                   } while (loop=='y');
                   return 0;
                   }  
Last edited on
It looks fine so far...couldn't find any problems (besides the fact that it isn't done...heh)
No problems here either, except for the fact that <stdlib.h> should be <cstdlib> when using C++. Anything like stddef.h, stdlib.h, stdio.h, etc. should be prefixed with a lowercase "C" and then remove the ".h" part. Here are the list of C headers and their C++ counterparts:

stdio.h = cstdio
stdlib.h = cstdlib
stddef.h = cstddef
string.h = cstring
math.h = cmath
time.h = ctime
ctype.h = cctype
assert.h = cassert
errno.h = cerrno
float.h = cfloat
limits.h = climits
locale.h = clocale
setjmp.h = csetjmp
signal.h = csignal
stdarg.h = cstdarg

The first few from stdio.h (cstdio) through ctype.h (cctype) are the ones that you'll encounter most often. The last one is for functions that take a variable number of arguments, and something that is not often used in C++ because function overloading helps to remove this need. The others aren't something you'll use until you get more into C++.

Edit: If you ever need a reference, the reference this site has is wonderful -
http://www.cplusplus.com/reference/
Last edited on
Here's a treasure trove of links to free tutorials and online books. Enjoy! I know I am.

http://freecomputerbooks.com/
Here is a link for some practices.
http://www.daniweb.com/forums/thread67837.html
Hello,
Here are some great links:
http://www.research.att.com/~bs/homepage.html
http://www.cpp-home.com/forum/index.php
http://www.cppreference.com/

And here is a simple program to have some fun with. Enjoy!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* Multiline comment
   
   In this program, you can 
   experiment with some fun
   stuff like changing color,
   making sounds and drawing
   lines in slow motion

  Dont forget to put comments
  in your program!

*/

// single line comment



// preprocessor directives
# include <iostream>

# include <windows.h> // included here for Beep( hertz, milliseconds );
                      // and Sleep( milliseconds ); functions


using namespace std;


// main
int main()
{
    
    // declare variable choice 
    // of type short    
    short choice;
    
    // display menu
    cout << "\t\tPlease make a selection from the list below:\n\n"
         << "\t\t1.Change color\n\n"
         << "\t\t2.Make sound\n\n"
         << "\t\t3.Draw line\n\n"
         << "\t\t4.Exit program\n\n"
         << "\t\t? ";
         
    cin >> choice;
    
              
    switch ( choice )
    {
           
           case 1:
                
                // clear screen
                system ( "cls" );
                
                // black background (0), blue text(9)
                system ( "color 09" );
                
                cout << "\n\n\t\tBlack background, blue text\n\n";
                
                //Experiment with numbers ranging
                // from 0 to 9, and A to F for
                // different colors
                                                
                break;
           
           case 2:
                
                // clear screen
                system ( "cls" );
                
                // make sounds
                Beep( 100, 100 ); 
                Beep( 500, 200 );
                Beep( 1000, 300 ); 
                Beep( 1500, 400 );
                Beep( 1900, 1000 );
                // the 1st number represents hertz, 
                // the second number represents 
                // the time duration in milliseconds
                // experiment with different numbers and
                // don't forget to include windows.h            
                
                
                break;
                
           case 3:
                
                system ( "cls" );
                
                cout << endl;
                
                for ( int i = 0; i < 80; i++ )
                {
                                        
                    // print line
                    cout << "-";
                    
                    // pause for 50 milliseconds before continuing
                    // experiment with different times
                    Sleep( 50 );
                    
                  
                }// end for
                
                break;
                
           case 4:
                
                // clear screen
                system ( "cls" );
                
                // display exit message
                cout << "\n\n\t\tThank you for using this program\n\n";
                
                // pause for 2 seconds
                Sleep( 2000 );
                
                // display exit message
                cout << "\n\n\t\tGoodbye!\n\n";
                Sleep( 2000 );
                
                // close program
                exit ( 1 );
                break;
                
           default:
                   
                   // clear the fail state
                   cin.clear();
                   
                   // ignore input error
                   cin.ignore( 1000, '\n' );
                   
                   // clear screen
                   system ( "cls" );
                   
                   // display error message
                   cout << "\n\n\t\tIncorrect Input!\n\n";
                   
                   // pause screen for 2 second
                   Sleep( 2000 );              
                   
                   break;    
           
    }// end switch
         


// pause the screen
    system ( "pause" );
    
}// end main 

Last edited on
Topic archived. No new replies allowed.