Forum Replies Created
- AuthorPosts
- S.ThananchayanParticipant
https://docs.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows
Here the basics of win 32 APIS.ThananchayanParticipant1234567891011121314#include <iostream><br />using namespace std;<br />int main()<br />{<br />float pi = 3.14;<br />int r;<br />double area;<br />cout << "Enter the radius: ";<br />cin >> r;<br />area = r * r * pi;<br />cout << "The area is " << area << "n";<br />return(0);<br /><br />} </iostream>
S.ThananchayanParticipant1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include <iostream><br />using namespace std;<br />void Menu();<br />int GetSomething();<br />inline void do_something (char* a)<br />{<br />cout << a << endl;<br />}<br />inline void do_something_else (char* b)<br />{<br />cout << b << endl;<br />}<br />inline void and_even_more (char* c)<br />{<br />cout << c << endl;<br />}<br />int main()<br />{<br />int loop;<br />int z;<br />for (loop = 0; loop < 10; loop++)<br />do_something("Dont taze me bro");<br />cout << "Press 1 or 2 for answer";<br />cin >>z;<br />if (z==1)<br />do_something_else("now you do what they told ya");<br />if (z==2)<br />and_even_more("Everyone fear the machine");<br />else<br /><br />Menu();<br /><br />int fun;<br />fun = GetSomething();<br /><br />switch (fun) {<br />case 1:<br />std::cout << "Wee" << std::endl;<br />break;<br />case 2:<br />std::cout << "Dude" << std::endl;<br />break;<br />case 3:<br />std::cout << "Quitting" << std::endl;<br />break;<br />default:<br />std::cout << "aInvalid selection" << std::endl;<br />break;<br />}<br />return 0;<br />}<br />void Menu()<br />{<br />std::cout << "--- Menu ---" << endl;<br />std::cout << "1=Wee" << endl;<br />std::cout << "2=Dude" << endl;<br />std::cout << "3=Quit" << endl;<br />}<br />int GetSomething()<br />{<br />int selection;<br />std::cout << "Enter Selection: ";<br />std::cin >> selection;<br />return selection;<br />}</iostream>S.ThananchayanParticipantThis one was interesting.
I ended up with this:123456789101112131415161718192021222324252627282930313233343536373839404142#include <iostream><br />using namespace std;<br />#include <vector><br />int main()<br />{<br />cout << "You are only allowed to enter 5" << endl ;<br />std::vector<int>::iterator iter;<br />std::vector</int><int> intVector;<br />int z;<br />cout << "enter a valuen";<br />cin >>z;<br />if (z <5)<br />return main();<br /><br />if (z >5)<br />return main();<br />else<br />for (int i=0; i<z; ++i)<br />intVector.push_back(z - i);<br />reverse(intVector.begin(), intVector.end());<br />for (int i=1; i<z+1; ++i)<br />intVector.push_back(z - i);<br />intVector.pop_back();<br />reverse(intVector.begin(), intVector.end());<br />for (iter = intVector.begin(); iter != intVector.end(); ++iter)<br />cout << *iter;<br />cout << endl;<br />reverse(intVector.begin(), intVector.end());<br />for (iter = intVector.begin() +1; iter != intVector.end()-1; ++iter)<br />cout << *iter;<br />cout << endl;<br />for (iter = intVector.begin() +2; iter != intVector.end()-2; ++iter)<br />cout << *iter;<br />cout << endl;<br />for (iter = intVector.begin() +3; iter != intVector.end()-3; ++iter)<br />cout << *iter;<br />cout << endl;<br />for (iter = intVector.begin() +4; iter != intVector.end()-4; ++iter)<br />cout << *iter;<br />cout << endl;<br />return (0);<br />}</int></vector></iostream>S.ThananchayanParticipantThanks~
That idea came from Al Stevens.
I just changed some of it.S.ThananchayanParticipantUnless something random seeds Rand. Rand will generate the same random numbers every time. In this case were using your computers time.
And every time you loop your system time is different So your numbers from say 3:43:01 to 3:43:02 will be different. Random enough for most applications.
Read Beginning C++ Game Programming
· ISBN-10: 1592002056
· ISBN-13: 978-1592002054
That’s where I learned thatS.ThananchayanParticipantEwwww thats got problems try this
1234567891011121314151617181920212223242526272829#include <iostream><br />template<class B1, class B2><br />class MyBook {<br />B1 book1;<br />B2 book2;<br />public:<br />MyBook(B1 b1, B2 b2) : book1(b1), book2(b2)<br />{ }<br />template</class><class B3, class B4><br />friend std::ostream& operator<<(std::ostream& os,<br />const MyBook<B3, B4>&);<br />};<br />template</class><class B1, class B2><br />std::ostream& operator<<(std::ostream& os,<br />const MyBook<B1, B2>& bb)<br />{<br />std::cout<<"My book has " << bb.book1 << ' ' << "pages" << std::endl;<br />std::cout<<"I just tore out " << bb.book1 - bb.book2 << ' ' << "pages" << std::endl;<br />std::cout<<"My book now has " << bb.book2 << ' ' << "pages" << std::endl;<br />return os;<br />}<br />int main()<br />{<br />int a = 970;<br />int b = 965;<br />MyBook<int,double> my_twothings(a, b);<br />std::cout << my_twothings << std::endl;<br />return 0;<br />}</class></iostream>S.ThananchayanParticipant12345678910111213141516#include <iostream><br />#include <windows.h> // WinApi header<br />using namespace<span style="font-size:1.0em"> std;<br />int main()<br />{<br />Beep(523,1000); //523 hertz (C5) for 500 milliseconds<span style="font-size:1.0em"><br />Beep(587,500);<br />Beep(659,500);<br />Beep(698,500);<br />Beep(784,500);<br />Beep(698,500);<br />Beep(659,500);<br />Beep(587,500);<br />Beep(523,1000);<br />return<span style="font-size:1.0em"> 0;<br />}</span></span></span></iostream>S.ThananchayanParticipantThats awsome I was thinking about this one.
This is the way I was going-
C12345678910111213141516171819202122#include <iostream>#include <algorithm>#include <vector>bool IsThis (int x) { return (x=1); }bool IsAnswer (int i) { return (((i%10)==2)&(i/100)==2); }int main () {int mynumbers;int mycount;std::vector<int> myscope;for (int x =100; x<300; x++) myscope.push_back(x);std::vector<int> myvector;for (int i=100; i<300; i++) myvector.push_back(i);mynumbers = (int) count_if (myscope.begin(), myscope.end(), IsThis);std::cout << "myvector contains " << mynumbers << " numbers between 100 and 300.n";mycount = (int) count_if (myvector.begin(), myvector.end(), IsAnswer);std::cout << "myvector contains " << mycount << " numbers that begin and end with 2.n";return 0;}S.ThananchayanParticipant//I finally got it werking…
12345678910DWORD i;<br />for (i=0; i<read; i++)<br />if("%i ", (unsigned char)buf){<br />printf ("%i ", (unsigned char)buf);<br />std::cout << "- This value was sent to the serial n "<br /><< " port and returned thru loopback." << std::endl ;<br />}<br />else;<br />if(!read )<br />std::cout << "No loopback installed.";S.ThananchayanParticipantYou need loop to hit random off system time
1234567891011121314151617181920212223242526272829303132#include <iostream><br />#include <ctime><br />using namespace std;<br />int main()<br />{<br />int a,b,c,d,e,f;<br />string g,h="a";<br />srand(time(0));<br />loop:<br />a = (rand()%10);<br />b = (rand()%10);<br />c = (rand()%10);<br />d = (rand()%10);<br />e = (rand()%10);<br />f = (rand()%10);<br />cout<<"n";<br />cout << a;<br />cout << b;<br />cout << c;<br />cout << d;<br />cout << e;<br />cout << f;<br />cout<<"n";<br />cout<<"n";<br />cout<<"To create a new random number, press a and then enter.";<br />getline (cin,g);<br />if (g==h){<br />goto loop;<br />}<br />cin.get();<br />}<br /></ctime></iostream> - AuthorPosts