Cpp | SoloLearn: Learn to code for FREE!



Please i need help i want to write a code in cpp how do i make a ball move up and then go back down? And can i write if and switch together?


6/8/2020 7:36:24 PM

mina beter

4 Answers

New Answer


mina beter Have you tried or thought any algorithm for it? If Yes then show


No i didn't


Show us the code first?


#include <iostream> #include <conio.h> #include <windows.h> #include <ctime> #include <cstdlib> using namespace std; class ping{ int wide; int high; int ballx; int bally; int tablex; int tabley; char dir; int speed; enum direction{lift=0,rieght}; public: void setup(){ wide=40; high=20; tabley=wide/2; tablex=high-0; bally=wide/2; ballx=high/2; } void drow(){ system("cls"); for(int i=0;i<=high;i++){ for(int u=0;u<=wide;u++){ if(i==0||u==0||u==wide) cout<<"*"; else if(i==tablex&&u==tabley||i==tablex&&u==tabley+1||i==tablex&&u==tabley+2||i==tablex&&u==tabley+3) cout<<"#"; else if(i==ballx&&u==bally) cout<<"O"; else if(ballz==ballx&&bally==bally) cout<<"O"; else cout<<" "; } cout<<"\n"; } } void wave(){ if(ballx<=10&&ballx>2){ ballx--; } else if(!(ballx<=10&&ballx>2)) ballx; Sleep(50); } void input(){ if(kbhit()){ char c=getch(); switch(c){ case 'a': dir=lif