The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
In C++: By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two; for example, the first 6 Fibonacci numbers are 0, 1, 1, 2, 3, 5. Write a program that asks the user for a number between 5 and 20 (inclusive) and then displays that many Fibonacci numbers. You must use a loop to calculate this! DonA????1t just cout the answer for each of the 15 possible answers. Also: Note that there is no last comma in the list.
Example of runs:


Here's my code so far:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  int x = 0;
  int fibNum = 0;
  cout << "How many Fibonacci numbers do you want? <5 to 20>: ";
  cin >> fibNum;
  while(x <= fibNum){
     x = x +1;
     cout << x << ", ";
  }
 Â
  return 0;
}
I can't get it to print out: 0, 1, 1, and etc. And I can't get it to not print a ',' at the last number.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll