My print is whack
Dec 8, 2015 at 9:54pm UTC
Hello, I am having a problem with printing the desktops... If I enter two or more desktops it takes the last one entered no matter what number you enter for the desktop, I want to be able to select a desktop according to its number to be printed. For example the first desktop added will have a number of 1, second desktop added will have a number of 2 and so on. ... I do have header files but I do not believe that the problem is within them.
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
#include <iostream>
#include <string>
#include <cctype>
#include "Components.h"
/*
* What to do:
* - Create a Help section
* - Create a Compare section
*/
/*
* Whats wrong:
* Printing desktop problem
*/
int selectionMenu(void );
int main()
{
int counter = 0;
std::cout << std::endl << "How many Desktops do you want to enter: " ;
int numDesktops;
std::cin >> numDesktops;
std::cin.get();
pcComponents *cptr = new pcComponents[numDesktops + 1];
int desktop;
int choice;
choice = selectionMenu();
while (choice < 4)
{
switch (choice)
{
case 1:
if (counter < numDesktops)
{
cptr[counter].add();
counter++;
}
else
std::cout << std::endl << "This is awkward... contact someone that is not me" ;
break ;
case 2:
std::cout << std::endl << "What desktop do you want to change: " ;
std::cin >> desktop;
std::cin.get();
while (desktop > counter || desktop < 0)
{
std::cout << std::endl << "You entered an invalid membership number, try again: " ;
std::cin >> desktop;
std::cin.get();
}
cptr[counter - 1].change();
break ;
case 3:
std::cout << std::endl << "What desktop do you want to print: " ;
std::cin >> desktop;
std::cin.get();
while (desktop > counter || desktop < 0)
{
std::cout << std::endl << "You entered an invalid membership number, try again: " ;
std::cin >> desktop;
std::cin.get();
}
cptr[counter - 1].print();
//cptr[desktop].print();
break ;
default :
std::cout << std::endl << "key pressed is invalid, try again: " ;
break ;
}
choice = selectionMenu();
}
return 0;
}
int selectionMenu(void )
{
int select;
std::cout << std::endl << "Please make a selection from our menu" ;
std::cout << std::endl << "=====================================" ;
std::cout << std::endl << "1 - Add Desktop Components" ;
std::cout << std::endl << "2 - Change Components" ;
std::cout << std::endl << "3 - Print Desktop Components" ;
std::cout << std::endl << "4 - Quit" << std::endl << std::endl;
std::cout << "Choice: " ;
std::cin >> select;
std::cin.get();
return select;
}
Last edited on Dec 8, 2015 at 9:57pm UTC
Dec 8, 2015 at 10:53pm UTC
cptr[counter desktop - 1].print()
Assuming the user thinks the first is 1 and not 0.
You have the same issue when "changing" a desktop.
Dec 8, 2015 at 11:00pm UTC
Thank you so much, I still can't figure out why I should've changed that. Can you explain why that change was supposed to be made?
Dec 8, 2015 at 11:19pm UTC
You wanted to print the desktop that was selected. desktop was the variable holding the selection, not counter .
Topic archived. No new replies allowed.